Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

behavior of parent and child for a signal handler

Tags:

unix

A process has a 'fork' call after a signal handler has been registered [for SIGINT]. what happens when SIGINT is sent through command line ? whether parent gets exited or child or both ? parent and child both are running infinite while loops.

like image 808
Puneet Avatar asked Feb 13 '13 11:02

Puneet


1 Answers

If you do fork (without further exec*) after a signal handler has been registered, the same signal handler will be used in parent and child processes. That is, if you do something other than exit in your SIGINT handler, neither parent nor child will exit (how SIGINT was sent is irrelevant here).

If you mean a SIGINT sent from the terminal (by vintr character which is usually Ctrl+C): it will be received by processes using the terminal as controlling terminal. That is, unless you detach child or parent from controlling terminal, both will react to Ctrl+C by calling your SIGINT handler.

like image 139
Anton Kovalenko Avatar answered Sep 20 '22 13:09

Anton Kovalenko