Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
Processes I<br />
func: argument specifies <strong>the</strong> address of a function<br />
- SIG_DFL handle in default way<br />
- SIG_IGN signal is to be ignored<br />
sig: is <strong>the</strong> signal name<br />
e.g.<br />
signal (SIGUSR1, SIG_IGN);<br />
- Call myintr function when SIGINT signal is generated:<br />
#include <br />
extern void myintr();<br />
if (signal (SIGINT, SIG_IGN) != SIG_IGN)<br />
signal (SIGINT, myintr);<br />
! Reliable Signals<br />
- Signals handlers remain installed after a signal occurs.<br />
- A process must be able to prevent selected signals from occurring when desired.<br />
- While a signal is being delivered to a process, that signal is blocked (held).<br />
BSD4.3 supports <strong>the</strong> concept of a signal mask:<br />
#include <br />
int mask; /* 32 signals one per bit */<br />
int oldmask;<br />
mask = sigmask(SIGQUIT) | sigmask(SIGINT);<br />
Want to block signals in critical region of code:<br />
oldmask = sigblock( mask );<br />
/* critical region */<br />
sigsetmask(oldmask); /* reset to what is was */<br />
System V use signal functions:<br />
sighold(SIGQUIT);<br />
sighold(SIGINT);<br />
/* critical region */<br />
sigrelse(SIGQUIT);<br />
sigrelse(SIGINT);<br />
BSD4.3 release one or more signals that are blocked:<br />
int flag = 0; /* global set when SIGINT occurs */<br />
for (; ;) {<br />
sigblock(sigmask(SIGINT));<br />
while (flag == 0)<br />
sigpause(0); /* wait for signal */<br />
/* signal has occurred, process it */<br />
...<br />
}<br />
System V version:<br />
int flag = 0; /* global set when SIGINT occurs */<br />
for (; ;) {<br />
sighold(SIGINT);<br />
while (flag == 0)<br />
sigpause(SIGINT); /* wait for signal */<br />
/* signal has occurred, process it */<br />
...}<br />
! Process Control<br />
Network programming involves <strong>the</strong> interaction of two or more processes. How are processes created, executed, and<br />
terminated?<br />
int fork(); /* system call */<br />
Creates a copy of <strong>the</strong> process that was executing. The process that executed <strong>the</strong> fork is <strong>the</strong> parent and <strong>the</strong> new<br />
117