Signals

Published on March 2017 | Categories: Documents | Downloads: 74 | Comments: 0 | Views: 382
of 3
Download PDF   Embed   Report

Comments

Content


6. SIGNALS
Signals are software generated interrupts that are sent to a process when a event happens.
Signals can be synchronously generated by an error in an application, such as SIGFPE
and SIGSEGV, but most signals are asynchronous. Signals can be posted to a process
when the system detects a software event, such as a user entering an interrupt or stop or a
ill re!uest from another process. Signals can also be come directly from the "S ernel
when a hardware event such as a bus error or an illegal instruction is encountered. #he
system defines a set of signals that can be posted to a process. Signal delivery is
analogous to hardware interrupts in that a signal can be bloced from being delivered in
the future. $ost signals cause termination of the receiving process if no action is taen by
the process in response to the signal. Some signals stop the receiving process and other
signals can be ignored. Each signal has a default action which is one of the following%
• #he signal is discarded after being received
• #he process is terminated after the signal is received
• & core file is written, then the process is terminated
• Stop the process after the signal is received
Each signal defined by the system falls into one of five classes%
• 'ardware conditions
• Software conditions
• Input(output notification
• Process control
• )esource control
$acros are defined in *signal.h+ header file for common signals.
#hese include%
SIG',P - (. hangup .( SIGI/# 0 (. interrupt .(
SIG1,I# 2 (. !uit .( SIGI33 4 (. illegal instruction .(
SIG&5)# 6 (. used by abort .( SIG7I33 8 (. hard ill .(
SIG&3)$ -4 (. alarm cloc .(
SIG9"/# -8 (. continue a stopped process .(
SIG9'3: 0; (. to parent on child stop or e<it .(
Signals can be numbered from ; to 2-.
&n e<ample of communicating process using signals is sig=tal.c%
(. sig=tal.c >>> E<ample of how 0 processes can tal .(
(. to each other using ill?@ and signal?@ .(
(. Ae will for?@ 0 process and let the parent send a few .(
(. signals to itBs child .(
(. cc sig=tal.c >o sig=tal .(
Cinclude *stdio.h+
Cinclude *signal.h+
void sighup?@D (. routines child will call upon sigtrap .(
void sigint?@D
void sig!uit?@D
main?@
E
int pidD
(. get child process .(
if ??pid F for?@@ * ;@
E
perror?GforG@D
e<it?-@D
H
if ?pid FF ;@
E (. child .(
signal?SIG',P,sighup@D (. set function calls .(
signal?SIGI/#,sigint@D
signal?SIG1,I#, sig!uit@D
for?DD@D (. loop for ever .(
H
else (. parent .(
E (. pid hold id of child .(
printf?GInP&)E/#% sending SIG',PInInG@D
ill?pid,SIG',P@D
sleep?2@D (. pause for 2 secs .(
printf?GInP&)E/#% sending SIGI/#InInG@D
ill?pid,SIGI/#@D
sleep?2@D (. pause for 2 secs .(
printf?GInP&)E/#% sending SIG1,I#InInG@D
ill?pid,SIG1,I#@D
sleep?2@D
H
H
void sighup?@
E
signal?SIG',P,sighup@D (. reset signal .(
printf?G9'I3:% I have received a SIG',PInG@D
H
void sigint?@
E
signal?SIGI/#,sigint@D (. reset signal .(
printf?G9'I3:% I have received a SIGI/#InG@D
H
void sig!uit?@
E
printf?G$y :&::J has 7illed meKKKInG@D
e<it?;@D
H

Sponsor Documents

Or use your account on DocShare.tips

Hide

Forgot your password?

Or register your new account on DocShare.tips

Hide

Lost your password? Please enter your email address. You will receive a link to create a new password.

Back to log-in

Close