signal programming question
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix Programming > signal programming question




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    signal programming question  
hectorchu@gmail.com


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
05-15-06 12:18 PM

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?






[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 12:07 PM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register