Unix Programming - signal programming question

This is Interesting: Free IT Magazines  
Home > Archive > Unix Programming > May 2006 > signal programming question





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author signal programming question
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?

Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com