Skip to content

Commit

Permalink
Fix FreeBSD ps command to retrieve zombie process state (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
Siva Mahadevan authored and daviddrysdale committed Jul 11, 2017
1 parent dc264fd commit c90e4e5
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion capsicum-test.cc
Expand Up @@ -50,7 +50,13 @@ char ProcessState(int pid) {
#endif
#ifdef __FreeBSD__
char buffer[1024];
snprintf(buffer, sizeof(buffer), "ps -p %d -o state | grep -v STAT", pid);
/*
* TODO(#18): Pdfork.Simple fails on FreeBSD because zombie processes are
* not reported by ps(1). As a temporary workaround, -a is used to retrieve
* the state of zombie processes. Remove this once FreeBSD starts reporting
* zombie processes with "sysctl kern.proc.pid.<pid>".
*/
snprintf(buffer, sizeof(buffer), "ps -a -p %d -o state | grep -v STAT", pid);
sig_t original = signal(SIGCHLD, SIG_IGN);
FILE* cmd = popen(buffer, "r");
usleep(50000); // allow any pending SIGCHLD signals to arrive
Expand Down

0 comments on commit c90e4e5

Please sign in to comment.