From b92fba5ca891fa6a1f4f3a6f12789b87ccc1b484 Mon Sep 17 00:00:00 2001 From: Leah Neukirchen Date: Mon, 17 Sep 2018 13:01:11 +0200 Subject: pwait: verify pids exist at parse time kill(pid, 0) will return ESRCH for nonexisting pids. (The other possible error, EPERM would indicate the pid exists.) --- NEWS.md | 2 ++ pwait.1 | 4 +++- pwait.c | 7 +++++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index 6bcfc4e..5d67ad4 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,7 @@ ## HEAD +* pwait: detect and warn for non-existing PID. + ## 0.6 (2018-06-19) * Add `-u` to print owner of process. diff --git a/pwait.1 b/pwait.1 index 6621b4f..9973747 100644 --- a/pwait.1 +++ b/pwait.1 @@ -1,4 +1,4 @@ -.Dd June 13, 2016 +.Dd September 17, 2018 .Dt PWAIT 1 .Os .Sh NAME @@ -22,6 +22,8 @@ Return 111 if any process exited non-successfully. .El .Sh EXIT STATUS .Ex -std +.Pp +Invalid pids elicit a warning message but are otherwise ignored. .Sh ERRORS Check these prerequisites if you see this error: .Bd -literal -offset Ds diff --git a/pwait.c b/pwait.c index e5f6fde..d32589d 100644 --- a/pwait.c +++ b/pwait.c @@ -184,6 +184,13 @@ usage: fprintf(stderr, "%s: invalid process id\n", argv[n]); continue; } + errno = 0; + kill(pid, 0); + if (errno == ESRCH) { + fprintf(stderr, "%s: no such process\n", argv[n]); + continue; + } + pids[m++] = pid; } -- cgit 1.4.1