By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,003 Members | 1,152 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,003 IT Pros & Developers. It's quick & easy.

Press Ctrl-C to terminal child process

P: 2
hi everybody!I'm newbie.I have a exercise about perl like this:
Creating 2 process P1(parent) P2 (child)
P1 get characters from keyboard
If press Ctrl-c P1 send a signal terminate P2
......................................
My ideal is :

Expand|Select|Wrap|Line Numbers
  1. $handle=IO::Socket::INET->(proto=>"tcp",
  2.                                     PeerAddr=>$host,
  3.                                      PeerPort=>$port)
  4. $handle->autoflush(1);
  5. die 'can't fork:$!' unless defined($pid=fork());
  6. if($pid) {
  7.  while(defined($line=<$handle>)){
  8. print STDOUT $line;
  9.         }
  10.    kill("TERM"=>$pid);
  11. }
  12. But my problem is press Ctrl-C.I think,can i creat a subroutine to respond to Ctrl-C like that:
  13. $SIG{INT}=\&killchild;
  14. sub killchild{
  15. .............
  16. }
  17.  
Please help me
Oct 23 '07 #1
Share this Question
Share on Google+
3 Replies


numberwhun
Expert Mod 2.5K+
P: 3,503
hi everybody!I'm newbie.I have a exercise about perl like this:
Creating 2 process P1(parent) P2 (child)
P1 get characters from keyboard
If press Ctrl-c P1 send a signal terminate P2
......................................
My ideal is :

Expand|Select|Wrap|Line Numbers
  1. $handle=IO::Socket::INET->(proto=>"tcp",
  2.                                     PeerAddr=>$host,
  3.                                      PeerPort=>$port)
  4. $handle->autoflush(1);
  5. die 'can't fork:$!' unless defined($pid=fork());
  6. if($pid) {
  7.  while(defined($line=<$handle>)){
  8. print STDOUT $line;
  9.         }
  10.    kill("TERM"=>$pid);
  11. }
  12. But my problem is press Ctrl-C.I think,can i creat a subroutine to respond to Ctrl-C like that:
  13. $SIG{INT}=\&killchild;
  14. sub killchild{
  15. .............
  16. }
  17.  
Please help me
Unfortunately, I don't have any experience with sockets so I cannot provide you an answer, but what I can say is that when you are posting code into the forum, please remember to surround that code in code tags. Read that link and you can see how to use them.

Regards,

Jeff
Oct 23 '07 #2

P: 2
Who can help me?i have a little time
Oct 24 '07 #3

numberwhun
Expert Mod 2.5K+
P: 3,503
Who can help me?i have a little time
Please know that while we understand you may be under an urgent deadline, we are not bound by that same deadline. If you do not get an answer, then I would go to another forum like perlmonks and ask your question.

Regards,

Jeff
Oct 24 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.