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.) --- pwait.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'pwait.c') 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