[Subject Prev][Subject Next][Thread Prev][Thread Next][Subject Index][Thread Index]

signals ??



Hello ,

Well i seem to be having problem passing signals betwen processe's in Linux ,
can some one tell me 
where am i bingling up .. i say had installed a signal handler for a signal
(infact tried all listed in Steven's) in a child process and when i send this
signal from the parent of this child it was getting lost (i mean handler
wasn't being called ) 
any comments ??
then is static global variables the way to pass reliably the information b/w
processe's ??

i am attaching a sample code saying what i was observing .. simple while (1)
loops in both parent and child with parent terminating when user presses
control-C and child is supposed to when it gets the SIGUSR1 from parent .

# include <sys/types.h>
# include <sys/wait.h>
# include <stdio.h>
# include <unistd.h>
# include <signal.h>
static int int_occured =0 ;
static int int_occured2 =0;
void handler(int i);
void usr1handler(int i);

void handler(int i)
{
 printf("OK I AM INSIDE THE HANDLER NOW  /n"); 
				/* this wasn't printed so we cannot print from inside the handler?? */

 sleep(2);   
 int_occured=1;
 kill(0,SIGUSR1);
 
}

void usr1handler(int i)
{
	printf("USR1 HAS BEEN THERE INTO ACTION NOW"); // basically it's to be used
to set int_ocured2 so that child also gets out of while loop //
	int_occured2=1;
        sleep(10);
	
}


main ()

{
	int chpid ;
	setpgrp();
	signal(SIGINT,handler);
	signal(SIGUSR1,SIG_IGN);
	
		while (!int_occured)
	{
		printf("not recvd. signal as of now !!, %d", getpid());
	}
	if ((chpid = fork()) ==0)
	{	
		signal(SIGINT,SIG_DFL);
		signal(SIGUSR1,usr1handler);
		printf("ok this is the good ol's child and VALUE OF INT!,%d",int_occured);	
		
		
		while(!(int_occured2))
		{
			printf("nahi main nahin maanonga  :)),%d , %d", int_occured,getpid());
			
		}
		printf("I AM INSIDE THE CHILD NOW");
	}
	else signal(SIGUSR1,SIG_IGN);

	printf("ok out of while loop ! "); // but never printed //
	exit(0);

}


With much modesty please point to this fella where i am goin wrong :(

Luv,
Nitin

____________________________________________________________________
Get free email and a permanent address at http://www.netaddress.com/?N=1