sending a kill to child process

Discussion in 'Perl Misc' started by AdamKaye-Smith, Aug 6, 2005.

  1. Hello ,


    I am trying to run a shell process from perl program and giving it a
    time limit to run in.

    To do this I use the perl function - alarm to set of a timer and when my
    program gets the %SIG{ALRM} signal it initiates a kill which is sent to
    all processes in the group ie kill 1 ,(-$$). This all works as expected.

    The problem is that this also kills my main perl program.

    I attempt to make the main perl program ignore the kill signal by doing
    the following :

    local $SIG{HUP} = 'IGNORE';


    but when I do this the child process also ignores the kill signal

    here is the test program:

    #!/usr/bin/perl -w

    $SIG{HUP} = 'DEFAULT';


    eval {
    local $SIG{HUP} = 'IGNORE';
    local $SIG{ALRM} = sub { kill 1 , (-$$) ; print "got rid of
    them\n"; };
    alarm 6;
    system ("sleep 30 ");
    alarm 0;
    };
    $SIG{HUP} = 'DEFAULT';

    print "going from here\n";



    How can I get this program to time out the system called process,
    without timing out the main perl program.

    I am running this under Fedora Core 4 op sys.


    At my wits end,


    Adam
     
    AdamKaye-Smith, Aug 6, 2005
    #1
    1. Advertising

  2. AdamKaye-Smith

    Guest

    AdamKaye-Smith <> wrote:
    > Hello ,
    >
    > I am trying to run a shell process from perl program and giving it a
    > time limit to run in.
    >
    > To do this I use the perl function - alarm to set of a timer and when my
    > program gets the %SIG{ALRM} signal it initiates a kill which is sent to
    > all processes in the group ie kill 1 ,(-$$). This all works as expected.
    >
    > The problem is that this also kills my main perl program.
    >
    > I attempt to make the main perl program ignore the kill signal by doing
    > the following :
    >
    > local $SIG{HUP} = 'IGNORE';
    >
    > but when I do this the child process also ignores the kill signal


    The child process inherits the parents sig handlers.


    >
    > here is the test program:
    >
    > #!/usr/bin/perl -w
    >
    > $SIG{HUP} = 'DEFAULT';
    >
    > eval {
    > local $SIG{HUP} = 'IGNORE';
    > local $SIG{ALRM} = sub { kill 1 , (-$$) ; print "got rid of
    > them\n"; };


    What if you put the local $SIG{HUP} = 'IGNORE'; inside the ALRM handler
    sub?

    Or just do a fork and exec, then the parent will have the exact pid
    it needs for doing the kill.

    Xho

    --
    -------------------- http://NewsReader.Com/ --------------------
    Usenet Newsgroup Service $9.95/Month 30GB
     
    , Aug 6, 2005
    #2
    1. Advertising

  3. Put the IGNORE inside the ALRM handler and works beautifully.


    Thank-you very much

    Adam


    wrote:
    > AdamKaye-Smith <> wrote:
    >
    >>Hello ,
    >>
    >>I am trying to run a shell process from perl program and giving it a
    >>time limit to run in.
    >>
    >>To do this I use the perl function - alarm to set of a timer and when my
    >>program gets the %SIG{ALRM} signal it initiates a kill which is sent to
    >>all processes in the group ie kill 1 ,(-$$). This all works as expected.
    >>
    >>The problem is that this also kills my main perl program.
    >>
    >>I attempt to make the main perl program ignore the kill signal by doing
    >>the following :
    >>
    >>local $SIG{HUP} = 'IGNORE';
    >>
    >>but when I do this the child process also ignores the kill signal

    >
    >
    > The child process inherits the parents sig handlers.
    >
    >
    >
    >>here is the test program:
    >>
    >>#!/usr/bin/perl -w
    >>
    >> $SIG{HUP} = 'DEFAULT';
    >>
    >> eval {
    >> local $SIG{HUP} = 'IGNORE';
    >> local $SIG{ALRM} = sub { kill 1 , (-$$) ; print "got rid of
    >>them\n"; };

    >
    >
    > What if you put the local $SIG{HUP} = 'IGNORE'; inside the ALRM handler
    > sub?
    >
    > Or just do a fork and exec, then the parent will have the exact pid
    > it needs for doing the kill.
    >
    > Xho
    >
     
    AdamKaye-Smith, Aug 6, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. I. Myself
    Replies:
    13
    Views:
    10,816
    Roger Upole
    May 6, 2006
  2. Nick Keighley

    Re: Kill Child Process

    Nick Keighley, Sep 9, 2008, in forum: C Programming
    Replies:
    0
    Views:
    528
    Nick Keighley
    Sep 9, 2008
  3. Ian Collins

    Re: Kill Child Process

    Ian Collins, Sep 9, 2008, in forum: C Programming
    Replies:
    0
    Views:
    518
    Ian Collins
    Sep 9, 2008
  4. Antoninus Twink

    Re: Kill Child Process

    Antoninus Twink, Sep 9, 2008, in forum: C Programming
    Replies:
    0
    Views:
    543
    Antoninus Twink
    Sep 9, 2008
  5. Z W
    Replies:
    0
    Views:
    179
Loading...

Share This Page