1

Programmatically check if a process is being run in the background

view story
linux-howto

http://stackoverflow.com – 2 questions: 1) Is there any Linux/Posix API to know if a process has been invoked as a background process? linux> myprogram & Can the code for myprogram detect that it has been invoked to run in the background (via &) ? 2) Is there any Linux/Posix API to make a process run in the background even if it has been started as a foreground process? I.E. somehow 'detach' from the shell at runtime.. (either detach itself from the shell completely, or run as a background process of the shell). linux> myprogram **** starting myprogram as a background job **** linux> The shell (HowTos)