2 questions:
1) Is there any Linux/Posix API to know if a process has been invoked as a background process?
linux> myprogram &
You might want to read the tty(4) man page. From what I understand, a process in the background does not have any /dev/tty
(so open
-ing that file would fail).
The TIOCNOTTY
ioctl should detach the calling process from its controlling terminal.
You might be interested by the isatty(3) function (e.g. to detect that your stdin or stdout is or not a terminal).