Procwait is a program that blocks until processes it tracks terminate. It is analogous to wait but is used to wait for any processes, not only its own children. When all of the tracked processes terminate, procwait terminates too. Procwait is a Linux program written in C99.

How it Works

A process is perceived to be running if there exists a directory called /proc/PID. However, simply relying on polling whether the directory still exists is racy: the tracked process can terminate and a new process can spawn with the same PID between polls. It may not be very likely in most use-cases as there are /proc/sys/kernel/pid_max available PIDs, but it is possible.

To reduce the possibility of a race condition procwait records the name and the start time of the tracked process at startup. The content of /proc/PID/stat is read every time a process is polled, and if the process' start time or the process' name doesn't match the recorded information the tracked process is considered terminated.

What's New in Version 1.3

The main thing the release introduces is the ability to match for program names directly with -n PNAME (--name PNAME) argument option instead of a numeric process ID. PNAME is checked against the executable name in /proc/PID/stat.

Previously it was possible to achieve something similar with pidof. It has its own peculiarities, though, especially when used with interpeted programs. When matching for a program name it often matches the given string the interpreter name (python, perl...) which makes it somewhat useless. The --name PNAME -option doesn't have this problem.

For complete list of changes, refer to the commit descriptions on github.