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

Re: signals ??



Hi ,
1.     The signal that you intend to send (SIGUSR1) to the child is not
lost but ignored because the fork has not occured yet and there is no child
process and the main process ignores it because of SIG_IGN. After you
create a child process , nowhere do you send a signal(SIGUSR1)  to the
child. The value "int_occured2" is never incremented and your child process
enters an infinite loop printing  "nahi main nahin maanonga" infinitely.
2. The printf inside the "handler"  fn will be printed if you use the
newline correctly ie., \n .
3. There are some other mistakes also in your program, I've rectified your
code , please see the attached file.
(See attached file: signals.c)

HTH
prateek





nitin mahajan <nitin.mahajan@xxxxxxx> on 18/05/2000 04:41:46 PM

Please respond to linux-india-programmers@xxxxxxxxxxxxxxxxxxxxx

To:   linux-india-programmers@xxxxxxxxxxxxxxxxxxxxx
cc:    (bcc: Prateek Gera/TMs/TCSDELHI/TCS)
Subject:  [LIP] 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

-----------------------------------------------------------------------
LIP is all for free speech.  But it was created for a purpose - to help
people discuss technical programming related issues about Linux.  If
your messages are counterproductive to this purpose, your privileges to
submit messages can and will be revoked.




Attachment: signals.c
Description: Binary data