









Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
This lecture was delivered by Dr. Ram Sai at Jaypee University of Engineering and Technology for Computers and Network Programming course. It includes: Network, Signal, Event, Handling, Programming, Software, Process, Interrupts, Kernel, Sigchld, Disposition
Typology: Slides
1 / 17
This page cannot be seen from the preview
Don't miss anything!










that^ an event^ has^ occurred. • Signals^ are^ sometimes
called^ software^ interrupts.
-^ Signals^ usually^
occur^ asynchronously,
mean^ that^ a process^ doesn't^ know
ahead^ of^ time^ exactly
when a^ signal^ will^ occur. • Signals^ can^ be^ sent^ –^ By^ one^ process^ to
another^ process
-^ By^ the^ kernel^ to^ a
process
-^ Every^ signal^ has
a^ disposition,^ which
is^ also called^ the^ action
associated^ with
the^ signal.
-^ We^ set^ the^ disposition
of^ a^ signal^ by^ calling the^ sigaction function.
-^ Provide^ a^ function
that^ is^ called^ whenever
a specific^ signal^ occurs. • Ignore^ a^ signal • Set^ the^ default^ disposition
for^ a^ signal
disposition^ to SIG_IGN.
a^ signal^ by^ setting its^ disposition^ to^
SIG_DFL.
-^ The^ default^ is^ normally
to^ terminate^ a^ process
on receipt^ of^ a^ signal,
with^ certain^ signals
also generating^ a^ core
image^ of^ the^ process
in^ its current^ working^ directory. • There^ are^ a^ few^ signals
whose^ default^ disposition is^ to^ be^ ignored:^ SIGCHLD
and^ SIGURG^ (sent
on the^ arrival^ of^ out‐
of‐band^ data)
Signal^ name^ Signal value^ Effect SIGHUP^1
Hangup SIGINT^2
Interrupt^ from keyboard SIGKILL^9
Kill^ signal SIGTERM^15
Termination^ signal SIGSTOP^ 17,19,
Stop^ the^ process
-^ These^ signal^ cannot
be^ caught^ or^ ignored.
-^ When^ killing^ a^ process
or^ series^ of^ processes,
it^ is^ common sense^ to^ start^ trying^
with^ the^ least^ dangerous
signal, SIGTERM. • That^ way,^ programs^ that
care^ about^ an^ orderly
shutdown get^ the^ chance^ to^ follow
the^ procedures^ that
they^ have been^ designed^ to^ execute
when^ getting^ the^ SIGTERM signal,^ such^ as^ cleaning
up^ and^ closing^ open
files.
-^ If^ you^ send^ a^ SIGKILL
to^ a^ process,^ you^ remove
any^ chance for^ the^ process^ to^ do
a^ tidy^ cleanup^ and^ shutdown,
which might^ have^ unfortunate
consequences.
-^ The^ normal^ function
prototype^ for^ signal is^ complicated^ by the^ level^ of^ nested^ parentheses.^ –^ void^ (*signal^ (int signo,
void^ (*func)^ (int)))^ (int);
-^ To^ simplify^ this,^ we
define^ the^ Sigfunc type
in^ unp.h header as:^ –^ typedef void^ Sigfunc(int); • stating^ that^ signal^ handlers
are^ functions^ with^ an
integer argument^ and^ the^ function
returns^ nothing^ (void).
The function^ prototype^ then
becomes
-^ Sigfunc *signal^ (int signo,
Sigfunc *func);
-^ A^ pointer^ to^ a^ signal
handling^ function^ is the^ second argument^ to^ the^ function,
as^ well^ as^ the^ return
value^ from the^ function.
-^ The^ sa_handler member
of^ the^ sigaction structure^ is^ set^ to
the^ func argument.
-^ SA_RESTART^ is
an^ optional^ flag.
When^ the^ flag is^ set,^ a^ system^ call
interrupted^ by^ this
signal will^ be^ automatically
restarted^ by^ the
kernel.
-^ If^ the^ signal^ being
caught^ is^ not^ SIGALRM,
we specify^ the^ SA_RESTART
flag,^ if^ defined.
-^ Some^ older^ systems,
notably^ SunOS^ 4.x, automatically^ restart
an^ interrupted^ system call^ by^ default^ and
then^ define^ the complement^ of^
this^ flag^ as^ SA_INTERRUPT.
the^ old action^ for^ the^ signal
as^ the^ return^ value
of^ the signal^ function.