16.05.2015 Views

Working with the Unix OS

Working with the Unix OS

Working with the Unix OS

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Processes I<br />

! Signals, Process Groups and Control Terminals<br />

Process structure<br />

p-pid:<br />

p-pgrp:<br />

assigned by kernel<br />

set by setpgrp()<br />

fd0:<br />

fd1:<br />

fd2:<br />

fdi:<br />

control<br />

tty:<br />

tty structure<br />

t_pgrp:<br />

…<br />

socket structure<br />

. so_pgrp:<br />

. set by fcnt1<br />

. socket structure<br />

(F_SETOWN)<br />

so_pgrp:<br />

process group for delivery<br />

of SIGIO, SIGURG signals<br />

process group for delivery of SIGINT,<br />

SIGQUIT, SIGHUP, SIGIO, SIGTSTP,<br />

SIGCONT, SIGWINCH signals<br />

! Disassociate from Control Terminal<br />

if (fork () ! = 0)<br />

exit(0); /* parent process */<br />

/* first child process */<br />

setpgrp(); /* change process group and lose control tty */<br />

! Don’t Reaquire a Control Terminal<br />

signal(SIGHUP, SIG_IGN);<br />

if (fork() != 0)<br />

exit(); /* first child process */<br />

/* second child process continues as daemon */<br />

! System V inittab File<br />

id:run-level:action:command-line<br />

tty01:2:respawn:getty #terminal line 1<br />

! Daemon Termination<br />

Both System V and BSD 4.3 use <strong>the</strong> SIGTERM signal to notify all processes that <strong>the</strong> system is going from<br />

multiuser to single-user. If it doesn’t terminate after 20 secs, SIGKILL is sent to <strong>the</strong> <strong>the</strong> process.<br />

! Handle SIGCLD Signals<br />

Tells kernel not to generate zombies form children.<br />

121

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!