commit 3fc721d074811416f4024976c472ddc396c4f00d
parent e96f0b9671d12a6977225ea22f7edf455331aa6e
Author: Jan Klemkow <j.klemkow@wemelug.de>
Date: Thu, 16 Apr 2020 22:34:15 +0200
ptty: wait for corrent child pid
Diffstat:
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/ptty.c b/ptty.c
@@ -79,8 +79,8 @@ main(int argc, char *argv[])
usage();
int mfd;
- pid_t pid = forkpty(&mfd, NULL, NULL, &ws);
- switch (pid) {
+ pid_t child = forkpty(&mfd, NULL, NULL, &ws);
+ switch (child) {
case -1:
die("forkpty");
case 0: /* child */
@@ -138,8 +138,11 @@ main(int argc, char *argv[])
break;
}
+ pid_t pid;
int status;
- waitpid(pid, &status, 0);
+ while ((pid = waitpid(-1, &status, WNOHANG)) > 0)
+ if (pid != child)
+ continue;
return WEXITSTATUS(status);
}