C -- signal and background process

Hi all,

Does a background process send a signal to its parent when completed? If so, how might i capture this signal?

I'm trying to write shell in c so that when a background process finishes, it prints a message to the console.

Thanks in advance for any advice.

SIGCHLD is the message. By default when a parent calls wait() it reaps the child process.

You can call waitpid(), wait() with WNOHANG to periodically check the status of a background process, so the background process can terminate asyncronously.
e.g., the behavior you see in

some command 2>&1> logfile &

You can also trap SIGCHLD and reap the child in a signal handler. Each of these has trade-offs.

Otherwise normal shell behavior is to wait() without WNOHANG, so the parent process is blocked on a wait() call. e.g., shell waits quietly after a fork() exec() this behavior

grep 'pattern'  very_largefile