in reply to Is Process Running In The Background?

It seemed plausible that I might be able to check and see if the process had a parent, but when I run a process in the background its not really forked, at least from what I can tell.
Assuming UNIX/POSIX behaviour:
  1. all processes except init have a parent process id (though the parent process may have already exit()ed).
  2. conceptually at least, the only way to start a new process is to fork() an existing one. Which explains 1.
  3. you can test if your program is running interactively by seeing if STDIN and STDOUT are connected to terminals (see -t). Note that plain backgrounded programs can still be interactive, while fully daemonized programs aren't.
  4. IOW, running interactively non-interactively isn't the same as running in the background. See also POSIX's tcgetpgrp() and tcsetpgrp().
  • Comment on Re: Is Process Running In The Background?