| hectorchu@gmail.com 2006-05-15, 7:18 am |
| Hi,
I'm trying to implement syscall semantics in userspace. One idea I've
tried is the following:
signal_test.c:
-------------------
#include <signal.h>
#include <unistd.h>
#include <sys/types.h>
pid_t childpid;
void handle(int sig)
{
puts("handle");
kill(childpid, SIGCONT);
}
int main(void)
{
if ((childpid = fork()) == 0)
execl("child", "child", 0);
signal(SIGUSR1, handle);
while(1);
}
child.c:
----------
#include <stdio.h>
#include <unistd.h>
#include <signal.h>
int main(void)
{
puts("hello");
kill(getppid(), SIGUSR1);
kill(getpid(), SIGSTOP);
puts("resumed");
}
I want to ensure that the output of running ./signal_test is:
hello
handle
resumed
But as far as I can see this is not guaranteed if the child program is
preempted between the two kill calls in the child, so that SIGCONT is
sent to the child before the child sends itself SIGSTOP. Is there a
way to fix this, or a better way entirely?
|