You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
Processes I<br />
(init process)<br />
- If process ID, process group ID, terminal group ID are all equal <strong>the</strong>n hangup signal “SIGHUP” is sent to<br />
each process <strong>with</strong> process group ID equal to terminating process<br />
- To prevent a child process from becoming a zombie<br />
signal (SIGCLD, SIG_IGN)<br />
! Process Relationships<br />
For each terminal to be activated, init process forks a copy of itself and each child process execs <strong>the</strong> getty program<br />
which sets terminal speed, output greeting message and waits for login name.<br />
getty execs <strong>the</strong> program login which checks your login name and password in /etc/passwd<br />
If <strong>the</strong> login is successful <strong>the</strong> login program sets <strong>the</strong> current working directory, chdir sets <strong>the</strong> group ID and user<br />
ID, setgid & setuid execs <strong>the</strong> shell program /bin/sh<br />
PID=<br />
l init init getty login sh<br />
fork exec exec exec<br />
To execute a command <strong>the</strong> shell forks a copy of itself and waits for child to terminate, <strong>the</strong> child execs <strong>the</strong> program,<br />
and when finished, it calls exit which terminates <strong>the</strong> child.<br />
! Job Control<br />
- consider process groups <strong>with</strong>/<strong>with</strong>out job-control<br />
BSD4.3 supports job-control - need to check system<br />
main()<br />
{<br />
printf ("lipid = %d, pgrp = %d\n ", getpid(), getpgrp());<br />
exit(0);<br />
}<br />
a.out<br />
Bourne, C & Korn shells<br />
a.out & a.out & twice in background<br />
(a.out & a.out &) from a subshell<br />
e.g.<br />
BSD C shell pid = 2530, pgrp = 2528<br />
pid = 2529, pgrp = 2528<br />
- process group leader<br />
- kill <strong>with</strong> a pid argument of zero sends a<br />
signal to all processes in <strong>the</strong> sender's process<br />
group<br />
! File Sharing<br />
There are 3 kernel tables used to access a file:<br />
- every process has a process table entry<br />
- file pointers in <strong>the</strong> process table point to<br />
entries in <strong>the</strong> file table (current file position)<br />
- i-node table (every open file has an entry)<br />
Since <strong>the</strong> i-node table does not keep <strong>the</strong> file's<br />
current position, an i-node entry for a. file can be<br />
shared by any number of processes.<br />
e.g. When two or more processes are reading <strong>the</strong><br />
same file at some point in time - <strong>the</strong> file position<br />
of one process must be independent of <strong>the</strong> o<strong>the</strong>r<br />
BSD Korn shell pid = 2530, pgrp = 2530<br />
pid = 2529, pgrp = 2529<br />
fd0:<br />
fd1:<br />
fd2:<br />
fdi:<br />
parent process file table i-node table<br />
table entry<br />
child process<br />
table entry<br />
fd0:<br />
fd1:<br />
fd2:<br />
fdi:<br />
o<strong>the</strong>r process<br />
table entry<br />
fd0:<br />
fd1:<br />
fd2:<br />
fdi:<br />
current file<br />
position<br />
i-node ptr<br />
current file<br />
position<br />
i-node ptr<br />
…<br />
…<br />
i-node<br />
information<br />
…<br />
119