Programmatically check if a process is being run in the background

前端 未结 4 864
粉色の甜心
粉色の甜心 2021-01-19 16:19

2 questions:

1) Is there any Linux/Posix API to know if a process has been invoked as a background process?

linux> myprogram &
4条回答
  •  有刺的猬
    2021-01-19 16:55

    A process is in the background if its parent shell process isn't suspended (waiting), which you can check through the PID.

    To put a process in the background (detach it completely from the shell at runtime), you use the daemon(3) function.

提交回复
热议问题