使用EXEC()给予和放大器,我们可以启动一个后台进程;作为参数? [英] Can we start a background process using exec() giving & as an argument?

查看:170
本文介绍了使用EXEC()给予和放大器,我们可以启动一个后台进程;作为参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果没有,我们怎么能启动一个后台进程用C?

If not, how can we start a background process in C?

推荐答案

在Unix中,执行exec()只是故事的一部分。

In Unix, exec() is only part of the story.

的exec()用于启动当前进程中的一个新的二进制。这意味着,当前在当前进程运行二进制将不再运行。

exec() is used to start a new binary within the current process. That means that the binary that is currently running in the current process will no longer be running.

所以,你调用exec()之前,你要调用fork()来创建一个新的过程,以便您当前的二进制可以继续运行。

So, before you call exec(), you want to call fork() to create a new process so your current binary can continue running.

通常情况下,能有当前的二进制等待新的进程退出,你调用wait *()家族的一员。这个函数将会把当前的进程睡眠直到你等待的过程就完成了。

Normally, to have the current binary wait for the new process to exit, you call one of the wait*() family. That function will put the current process to sleep until the process you are waiting is done.

因此​​,为了创造一个背景的过程,当前的进程应该只跳过呼叫等待。

So in order to create a "background" process, your current process should just skip the call to wait.

这篇关于使用EXEC()给予和放大器,我们可以启动一个后台进程;作为参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆