2个问题:
1) 是否有任何 Linux/Posix API 可以知道某个进程是否已被调用为后台进程?
linux> myprogram &
Run Code Online (Sandbox Code Playgroud)
是否可以myprogram检测到它已被调用在后台运行的代码(通过&)?
2) 是否有任何 Linux/Posix API 可以使进程在后台运行,即使它已作为前台进程启动?IE 以某种方式在运行时从外壳“分离”..(要么将自身完全从外壳分离,要么作为外壳的后台进程运行)。
linux> myprogram
**** starting myprogram as a background job ****
linux>
Run Code Online (Sandbox Code Playgroud)
shell 提示应该立即返回给我,因为它myprogram已经与 shell 分离并在后台运行