Welcome to Scribd, the world's digital library. Read, publish, and share books and documents. See more
Download
Standard view
Full view
of .
Look up keyword
Like this
0Activity
0 of .
Results for:
No results containing your search query
P. 1
Slides Pratica Signals e Pipes

Slides Pratica Signals e Pipes

Ratings: (0)|Views: 4|Likes:
Published by André Perdigão

More info:

Categories:Types, School Work
Published by: André Perdigão on Oct 18, 2011
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as PDF, TXT or read online from Scribd
See more
See less

10/18/2011

pdf

text

original

 
DepartmentofInformaticsEngineering
FCTUCUniversityofCoimbra
Signals
Asignalrepresentsanasynchronouseventwhichanapplicationmust(should?can?)processTheprogrammercanregisteraroutinetohandlesucheventsExamples:TheuserhitsCtrl+C
-7
SIGINTThesystemrequeststheapplicationtoterminateTheprogramtriedtowritetoaclosedchannel
-7
SIGTERM
-7
SIGPIPE
Process
f·i·~t··~·i·g·i·~tj;~·~d·I~·~(·)·{·
~II
processsignal
~.!..
 
Signals(2)
Signalscanbeinoneoffourstates:Blocked:Uponarrival,theyarestoredinaqueueuntiltheprocessunblocksthem.Then,theyaredelivered.Ignored:Uponarrival,theyarediscarded.Itisasiftheyhadneverexisted.BeingHandled:Theyareredirectedtoasignalhandlerwhichiscalled.Noneoftheabove:Non-handled,non-blockedorignoredsignals.Uponarrival,theycauseprogramtermination.Somesignalscannotbeignoredorhandled(e.g.SIGKILL)Whenaprocessstarts,signalsareontheir"defaultbehavior".Someareignored,mostareinthe"non-handled,non-blockednorignoredstate".Ifasignaloccurs,theprocesswilldie.
BasicSignalRoutines
prototypeofthe
typedefvoid(*sighandler_t)(int);-
handlerroutine
sighandler_tsignal(intsignum,sighandler_thandler);Redirectsacertainsignal
(signum)
toahandlerroutine.intkill(pid_tpid,intsig);SendsasignaltoacertainprocessidentifiedbyaPID.(Note:ifpidis0,sendstoallprocessesinthecurrentprocessgroup.)intpauset):Blockstheprocessuntilasignalisreceived.
..............................................................
iintsigaction();iintsigprocmask();!intsigpending();!intsigsuspend();
...............................
_
.
Note:
ThesearetherecommendedPOSIXroutines.Wearenotgoingtocoverthemhere.TheproblemwithsignalOisthatincertaincasesitsbehaviorisundefinedacrosssystems.
 
Handlingasignal
[·~·~i·d···~·ig"i~t·(i·~t···~·ig~·~~·)····{············.
charoption[2];printf("\n"Cpressed.Doyouwanttoabort?");scanf("%ls",option);if(option[0]
==
'y'){printf("Ok,byebye!\n");exit(0);
}}
intmain()
{
II
RedirectsSIGINTtosigint()signal(SIGINT,sigint);
II
Dosomework!while(1){printf("Doingsomework...\n");sleep(l);
}
return0;
}
SpecialconstantsinsignalOIsignal(SIGINT,
SIG_IGN)
I
Ignores
SIGINT
Isignal(SIGINT,
SIG_DFL)
I
Restores
SIGINT
toits"default"handling

You're Reading a Free Preview

Download
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->