Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fall 2013 updates for lecture 06 on Process Groups, Sessions, Job Con…
…trol, Signals
  • Loading branch information
jschauma committed Oct 8, 2013
1 parent 790b3ec commit d15cd98
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 36 deletions.
3 changes: 2 additions & 1 deletion 06-signals/eintr.c
Expand Up @@ -37,8 +37,9 @@ main(void) {
/* NOTREACHED */
}

/* Ensure interrupted system calls are restarted rather than
* setting errno to EINTR. */
sa.sa_flags = SA_RESTART;

if (sigaction(SIGQUIT, &sa, NULL) == -1) {
fprintf(stderr, "Unable to establish signal handler for SIGQUIT: %s\n",
strerror(errno));
Expand Down
2 changes: 2 additions & 0 deletions 06-signals/file
@@ -0,0 +1,2 @@
this is one sentence
this another
2 changes: 1 addition & 1 deletion 06-signals/reentrant.c
Expand Up @@ -28,7 +28,7 @@ my_alarm(int signo)

write(STDOUT_FILENO, "in signal handler\n", 18);
if ((rootptr = getpwnam("root")) == NULL) {
fprintf(stderr, "no 'root' found!\n");
write(STDERR_FILENO, "no 'root' found!\n", 17);
exit(1);
}
alarm(1);
Expand Down
44 changes: 12 additions & 32 deletions 06-signals/slides.tex
Expand Up @@ -351,17 +351,18 @@ \subsection{Process Groups}
\begin{center}
\begin{picture}(150,30)
\thinlines
\put(0,0){\framebox(130,30){}}
\put(10,25){{\tt \#include <unistd.h>}}
\put(10,18){{\tt pid\_t getpgrp(void);}}
\put(10,13){{\tt pid\_t getpgid(pid\_t {\em pid});}}
\put(30,5){Returns: process group ID if OK, -1 otherwise}
\put(0,0){\framebox(130,25){}}
\put(10,20){{\tt \#include <unistd.h>}}
\put(10,13){{\tt pid\_t getpgrp(void);}}
\put(10,8){{\tt pid\_t getpgid(pid\_t {\em pid});}}
\put(55,3){Returns: process group ID if OK, -1 otherwise}
\end{picture}
\end{center}
\Normalsize
\begin{itemize}
\item in addition to having a PID, each process also
belongs to a process group
belongs to a process group (collection of processes
assocaited with the same job / terminal)
\item each process group has a unique process group ID
\item process group IDs (like PIDs) are positive integers and can
be stored in a {\tt pid\_t} data type
Expand Down Expand Up @@ -463,7 +464,7 @@ \subsection{Process Groups and Sessions}
\includegraphics[angle=-90,scale=0.6]{pics/pscat.eps}
\end{center}
\begin{verbatim}
$ ps -o pid,ppid,pgrp,sess,comm | ./cat1 | ./cat2
$ ps -o pid,ppid,pgid,sess,comm | ./cat1 | ./cat2
PID PPID PGRP SESS COMMAND
1989 949 7736 949 ps
1990 949 7736 949 cat1
Expand All @@ -478,7 +479,7 @@ \subsection{Job Control}
\end{center}
\addvspace{.5in}
\begin{verbatim}
$ ps -o pid,ppid,pgrp,sess,comm
$ ps -o pid,ppid,pgid,sess,comm
PID PPID PGRP SESS COMMAND
24251 24250 24251 24251 ksh
24620 24251 24620 24251 ps
Expand All @@ -491,7 +492,7 @@ \subsection{Job Control}
\end{center}
\addvspace{.5in}
\begin{verbatim}
$ ps -o pid,ppid,pgrp,sess,comm
$ ps -o pid,ppid,pgid,sess,comm
PID PPID PGRP SESS COMMAND
24251 24250 24251 24251 ksh
24620 24251 24620 24251 ps
Expand All @@ -507,7 +508,7 @@ \subsection{Job Control}
\begin{verbatim}
$ dd if=/dev/zero of=/dev/null bs=512 count=2048000 >/dev/null 2>&1 &
[1] 24748
$ ps -o pid,ppid,pgrp,sess,comm
$ ps -o pid,ppid,pgid,sess,comm
PID PPID PGRP SESS COMMAND
24251 24250 24251 24251 ksh
24748 24251 24748 24251 dd
Expand Down Expand Up @@ -778,26 +779,6 @@ \subsection{{\tt signal(3)}}
\item or the address of a function which should catch or handle a signal
\end{itemize}

\subsection{{\tt signal(3)}}
\small
\setlength{\unitlength}{1mm}
\begin{center}
\begin{picture}(150,22)
\thinlines
\put(0,0){\framebox(130,22){}}
\put(10,17){{\tt \#include <signal.h>}}
\put(10,10){{\tt void (*signal(int {\em signo}, void (*func)(int)))(int);}}
\put(30,3){Returns: previous disposition of signal if OK, {\tt SIG\_ERR} otherwise}
\end{picture}
\end{center}
\Normalsize
{\em func} can be:
\begin{itemize}
\item {\tt SIG\_IGN} which requests that we ignore the signal {\tt signo}
\item {\tt SIG\_DFL} which requests that we accept the default action for signal {\tt signo}
\item or the address of a function which should catch or handle a signal
\end{itemize}

\subsection{Signal Examples}
\begin{verbatim}
$ cc -Wall siguser.c
Expand Down Expand Up @@ -886,7 +867,7 @@ \subsection{Signal Queuing}
^\sig_quit: exiting (3)
sig_quit: caught SIGQUIT (4), now sleeping
sig_quit: exiting (4)
$
[...]
\end{verbatim}

(Note that "simultaneously" delivered signals may be "merged" into one.)
Expand Down Expand Up @@ -926,7 +907,6 @@ \subsection{Signal Queuing}
sig_quit: caught SIGQUIT (4), now sleeping
sig_quit: exiting (4)
[...]
$
\end{verbatim}

\subsection{Program Startup}
Expand Down
4 changes: 2 additions & 2 deletions html/index.html
Expand Up @@ -375,9 +375,9 @@ <H3><A name="syllabus">Syllabus</A>:</H3>

<TD>Process Groups, Sessions, Signals</TD>

<TD>Stevens: Chapter 10</TD>
<TD>Stevens: Chapter 9, 10</TD>

<TD width="25%"><em>Note: Tuesday class!</em><br>
<TD width="25%">
<A href="lecture06.pdf">Lecture
Slides</A><BR>
<a
Expand Down

0 comments on commit d15cd98

Please sign in to comment.