waitpid() with WUNTRACED flag? (was Re: Hang on ctrl+Z after the MPSAFE tsleep/wakeup commit)
YONETANI Tomokazu
qhwt+dfly at les.ath.cx
Mon Dec 26 16:28:43 PST 2005
On Tue, Dec 27, 2005 at 09:15:54AM +0900, YONETANI Tomokazu wrote:
> By the way, here's the code I forgot attaching in the previous message.
*blush*
#include <sys/types.h>
#include <sys/wait.h>
#include <err.h>
#include <errno.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
int
main()
{
const char *editor = "/usr/bin/vi";
const char *name;
pid_t pid, caught;
int sig;
int st;
if (getenv("EDITOR") != NULL)
editor = getenv("EDITOR");
if ((name = strrchr(editor, '/')) != NULL)
++name;
else
name = editor;
if ((pid = fork()) < 0)
err(1, "fork");
if (pid == 0)
return execlp(editor, name, NULL);
#if 0
sleep(1);
killpg(getpgrp(), SIGSTOP);
#endif
for (;;) {
caught = waitpid(pid, &st, WUNTRACED);
warnx("waitpid returned %d\n", caught);
errno = WEXITSTATUS(st);
if (caught == -1)
return 1;
else if (WIFSTOPPED(st)) {
sig = WSTOPSIG(st);
warnx("WSTOPSIG(%d) = %d\n", st, sig);
sig = SIGSTOP;
raise(sig);
warnx("after raise(%d)\n", sig);
}
else if (WIFEXITED(st))
return errno;
else
return 1;
}
return 0;
}
More information about the Bugs
mailing list