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:
- all processes except init have a parent process id (though the parent process may have already exit()ed).
- conceptually at least, the only way to start a new process is to fork() an existing one. Which explains 1.
- 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.
- IOW, running
interactively non-interactively isn't the same as running in the background. See also POSIX's tcgetpgrp() and tcsetpgrp().