Process in background mode trying to read from stdin

1k Views Asked by At

In Linux/Unix when a process in the background mode tries to read from stdin it gets terminated. What is causing this termination ? There is no core file. So it doesn't look like termination is by a signal that generates core.

1

There are 1 best solutions below

0
On

One reason for termination could be a signal.

When process are not connected directly to a tty device, stdin/stdout are typically handled with pipes. The pipe(7) man page says:

If all file descriptors referring to the read end of a pipe have been closed, then a write(2) will cause a SIGPIPE signal to be generated for the calling process.

However, this applies only to writing.

For reading,

if all file descriptors referring to the write end of a pipe have been closed, then an attempt to read(2) from the pipe will see end-of-file (read(2) will return 0).

It is quite possible that the program, when it cannot read anything, decides to terminate. (What else could it do?)