|
17 | 17 | \item signal categories: |
18 | 18 | \begin{itemize} |
19 | 19 | \item \emsl{asynchronous events} happening independently of the main program |
20 | | - flow, eg. a signal sent from another process, a timer expiration |
| 20 | + flow, e.g. a signal sent from another process, a timer expiration |
21 | 21 | (\texttt{SIGALRM}), terminal disconnect (\texttt{SIGHUP}), or pressing |
22 | 22 | \texttt{Ctrl-C} (\texttt{SIGINT}) |
23 | | - \item \emsl{exceptions} caused by a running process, eg. |
| 23 | + \item \emsl{exceptions} caused by a running process, e.g. |
24 | 24 | attempt to access a restricted area of memory (\texttt{SIGSEGV}) |
25 | 25 | \end{itemize} |
26 | 26 | \end{itemize} |
|
64 | 64 | \begin{slide} |
65 | 65 | \sltitle{Introduction to signals (continued)} |
66 | 66 | \begin{itemize} |
67 | | -\item it is the simplest interprocess communication -- it only carries |
| 67 | +\item it is the simplest inter process communication -- it only carries |
68 | 68 | information that an event happened |
69 | 69 | \begin{itemize} |
70 | 70 | \item there is a real-time POSIX extension that allows for more information, |
|
92 | 92 |
|
93 | 93 | \begin{slide} |
94 | 94 | \sltitle{Sending signals} |
| 95 | +ifdef([[[NOSPELLCHECK]]], [[[ |
95 | 96 | \texttt{int \funnm{kill}(pid\_t \emph{pid}, int \emph{sig});} |
| 97 | +]]]) |
96 | 98 | \begin{itemize} |
97 | | -\item sends signal \emph{sig} to a process or a process group |
98 | | -based on value of \emph{pid}: |
| 99 | +\item sends signal \emph{\texttt{sig}} to a process or a process group |
| 100 | +based on value of \emph{\texttt{pid}}: |
99 | 101 | \begin{itemize} |
100 | | - \item \texttt{> 0} \dots{} to process with \emph{pid} |
| 102 | + \item \texttt{> 0} \dots{} to process with \emph{\texttt{pid}} |
101 | 103 | \item \texttt{== 0} \dots{} to all processes in the same group |
102 | 104 | \item \texttt{== -1} \dots{} to all aside from system processes |
103 | 105 | \item \texttt{< -1} \dots{} to processes in a group \texttt{abs(pid)} |
|
148 | 150 | \end{itemize} |
149 | 151 |
|
150 | 152 | Signals \texttt{SIGKILL} and \texttt{SIGSTOP} \emsl{always} trigger an implicit |
151 | | -action, ie. exit or stop, respectively. |
| 153 | +action, i.e. exit or stop, respectively. |
152 | 154 | \end{slide} |
153 | 155 |
|
154 | 156 | \begin{itemize} |
155 | 157 | \item Creating a core dump means to store the contents of the process virtual |
156 | 158 | address space to a file. Usually such file has a word \texttt{core} in its |
157 | | -filename. Some systems, eg. macOS, may not generate core dumps by default even |
| 159 | +filename. Some systems, e.g. macOS, may not generate core dumps by default even |
158 | 160 | if its for signals with default core dump action. |
159 | 161 | \item Most of the signals implicitly terminate the process, some create a core |
160 | 162 | dump on top of that to enable a post-mortem analysis. |
|
185 | 187 | \emsl{Detected errors:} |
186 | 188 |
|
187 | 189 | \begin{tabular}{ll} |
188 | | -\texttt{SIGBUS} & bus error, eg. wrong alignment (core) \\ |
| 190 | +\texttt{SIGBUS} & bus error, e.g. wrong alignment (core) \\ |
189 | 191 | \texttt{SIGFPE} & floating point exception (core) \\ |
190 | 192 | \texttt{SIGILL} & illegal instructions (core) \\ |
191 | 193 | \texttt{SIGSEGV} & segmentation violation (core) \\ |
|
231 | 233 | \item If such a signal is masked while the signal is being delivered, the |
232 | 234 | program behavior is undefined. |
233 | 235 | \end{itemize} |
234 | | -\item Bottom line is that if a hardware generated error is real (ie. the signal |
| 236 | +\item Bottom line is that if a hardware generated error is real (i.e. the signal |
235 | 237 | is not send via \funnm{kill} or similar functions), the process may never get |
236 | 238 | over that error at all. It is not safe to ignore such errors, continue after |
237 | 239 | returning from a handler, or mask such signals. You can catch such signals |
|
275 | 277 | know what you are doing. For example, if a running process does not respond to |
276 | 278 | user input nor any other signal. Many applications, mainly daemons, rely on the |
277 | 279 | fact that they are sent \texttt{SIGTERM} on termination, which they often handle |
278 | | -and perform pre-exit actions. For example, flushing the database, removing |
279 | | -temporary files and file locks, etc. So, do not use \texttt{SIGKILL} right away |
| 280 | +and perform actions before exit. For example, flushing the database, removing |
| 281 | +temporary files and file locks, etc. So, do not use \texttt{SIGKILL} right away |
280 | 282 | only because "it's the simplest way to kill a process" as you might run in |
281 | 283 | trouble. |
282 | 284 | \item Example on using \texttt{SIGQUIT} on Solaris: |
|
356 | 358 |
|
357 | 359 | %%%%% |
358 | 360 |
|
| 361 | +ifdef([[[NOSPELLCHECK]]], [[[ |
359 | 362 | \pdfbookmark[1]{sigaction}{sigaction} |
| 363 | +]]]) |
360 | 364 |
|
361 | 365 | \begin{slide} |
362 | 366 | \sltitle{Setting actions for signals} |
| 367 | +ifdef([[[NOSPELLCHECK]]], [[[ |
363 | 368 | \begin{minipage}{\slidewidth}\vspace{-1\baselineskip}\texttt{\begin{tabbing} |
364 | 369 | int \funnm{sigaction}(\=int \emph{sig}, |
365 | 370 | const struct sigaction *\emph{act},\\\> struct sigaction *\emph{oact}); |
| 371 | +]]]) |
366 | 372 | \end{tabbing}} |
367 | 373 | \end{minipage} |
368 | 374 | \begin{itemize} |
369 | | -\item assigns an action \emph{act} for a signal \emph{sig}, |
370 | | -previous setting is returned in \emph{oact}, if non-zero |
| 375 | +\item assigns an action \emph{\texttt{act}} for a signal \emph{\texttt{sig}}, |
| 376 | +previous setting is returned in \emph{\texttt{oact}}, if non-zero |
371 | 377 | \item structure \texttt{sigaction} contains: |
372 | 378 | \begin{itemize} |
| 379 | +ifdef([[[NOSPELLCHECK]]], [[[ |
373 | 380 | \item \texttt{void (*\emph{sa\_handler})(int)} \dots{} \texttt{SIG\_DFL}, |
374 | | - \texttt{SIG\_IGN}, or a handler address (ie. a handler function name) |
375 | | - \item \texttt{sigset\_t \emph{sa\_mask}} \dots{} signals blocked while in |
376 | | - handler; plus \emph{sig} is blocked by default |
377 | | - \item \texttt{int \emph{sa\_flags}} \dots{} \texttt{SA\_RESETHAND} (handler |
| 381 | +]]]) |
| 382 | + \texttt{SIG\_IGN}, or a handler address (i.e. a handler function name) |
| 383 | + \item ifdef([[[NOSPELLCHECK]]], [[[\texttt{sigset\_t \emph{sa\_mask}}]]]) |
| 384 | + \dots{} signals blocked while in |
| 385 | + handler; plus \emph{\texttt{sig}} is blocked by default |
| 386 | + \item ifdef([[[NOSPELLCHECK]]], [[[\texttt{int \emph{sa\_flags}}]]]) |
| 387 | + \dots{} \texttt{SA\_RESETHAND} (handler |
378 | 388 | is reset to \texttt{SIG\_DFL} at the moment the signal is delivered), |
379 | 389 | \texttt{SA\_RESTART} (restart pending calls), \texttt{SA\_NODEFER} |
380 | | - (do not block \emph{sig} while in handler) |
| 390 | + (do not block \emph{\texttt{sig}} while in handler) |
381 | 391 | \end{itemize} |
382 | 392 | \end{itemize} |
383 | 393 | \end{slide} |
384 | 394 |
|
385 | 395 | \begin{itemize} |
386 | 396 | \item If \texttt{act == NULL} you only get the present setting and nothing is |
387 | 397 | changed. If not interested in previous setting, use \texttt{NULL} for |
388 | | -\emph{oact}. |
| 398 | +\emph{\texttt{oact}}. |
389 | 399 | \item If \texttt{SA\_RESTART} is not set, the system call interrupted by the |
390 | 400 | signal will return an error with \texttt{errno} set to \texttt{EINTR} (some |
391 | 401 | calls actually return directly the \texttt{errno} value but that is not relevant |
|
400 | 410 | to make sure the signal is not delivered in the wrong time (for example, the |
401 | 411 | signal is delivered within a function and the same function is called from the |
402 | 412 | handler, and the function is not ready for that). Minimal set of functions |
403 | | -that must be \emsl{\emph{async-signal-safe}} is listed in SUSv4 in section |
| 413 | +that must be ifdef([[[NOSPELLCHECK]]], [[[\emsl{\emph{async-signal-safe}}]]]) |
| 414 | +is listed in SUSv4 in section |
404 | 415 | \emph{System Interfaces: General Information $\Rightarrow$ Signal Concepts |
405 | 416 | $\Rightarrow$ Signal Actions (2.4.3)}. Systems can extend the list, of course. |
406 | 417 | Whether a function is safe to use in a signal handler or not should be |
|
485 | 496 |
|
486 | 497 | %%%%% |
487 | 498 |
|
| 499 | +ifdef([[[NOSPELLCHECK]]], [[[ |
488 | 500 | \pdfbookmark[1]{sigprocmask, sigpending}{sigblock} |
| 501 | +]]]) |
489 | 502 |
|
490 | 503 | \begin{slide} |
491 | 504 | \sltitle{Signal blocking} |
492 | 505 | \begin{itemize} |
493 | 506 | \item blocked signals are delivered to the process after getting unblocked again |
494 | 507 | \end{itemize} |
495 | 508 | \begin{minipage}{\slidewidth}\texttt{\begin{tabbing} |
| 509 | +ifdef([[[NOSPELLCHECK]]], [[[ |
496 | 510 | int \funnm{sigprocmask}(\=int \emph{how}, const sigset\_t *\emph{set},\\ |
497 | 511 | \>sigset\_t *\emph{oset}); |
| 512 | +]]]) |
498 | 513 | \end{tabbing}} |
499 | 514 | \end{minipage} |
500 | 515 | \begin{itemize} |
|
506 | 521 | \funnm{sigdelset}(), \funnm{sigemptyset}(), \funnm{sigfillset}(), |
507 | 522 | \funnm{sigismember}() |
508 | 523 | \end{itemize} |
| 524 | +ifdef([[[NOSPELLCHECK]]], [[[ |
509 | 525 | \texttt{int \funnm{sigpending}(sigset\_t *\emph{set});} |
| 526 | +]]]) |
510 | 527 | \begin{itemize} |
511 | 528 | \item returns a mask for the signals pending for delivery |
512 | 529 | \end{itemize} |
|
526 | 543 | \pageref{REALTIMEEXTENSIONS} and the use of \texttt{SA\_SIGINFO}), signals are |
527 | 544 | delivered through a queue and multiple signals are never squeezed into one |
528 | 545 | delivery. |
529 | | -\item Both arguments \emph{oset} and \emph{set} may be \texttt{NULL}. If both |
530 | | -are \texttt{NULL} in the same invocation of the function, nothing happens. |
| 546 | +\item Both arguments \emph{\texttt{oset}} and \emph{set} may be \texttt{NULL}. |
| 547 | +If both are \texttt{NULL} in the same invocation of the function, nothing |
| 548 | +happens. |
531 | 549 | \end{itemize} |
532 | 550 |
|
533 | 551 | %%%%% |
|
570 | 588 | %%%%% |
571 | 589 |
|
572 | 590 | \label{SIGWAIT} |
| 591 | +ifdef([[[NOSPELLCHECK]]], [[[ |
573 | 592 | \pdfbookmark[1]{pause, sigsuspend, sigwait}{sigwait} |
| 593 | +]]]) |
574 | 594 |
|
575 | 595 | \begin{slide} |
576 | 596 | \sltitle{Waiting for a signal} |
|
579 | 599 | \item suspends the caller until delivery of a signal that is not blocked or |
580 | 600 | ignored |
581 | 601 | \end{itemize} |
| 602 | +ifdef([[[NOSPELLCHECK]]], [[[ |
582 | 603 | \texttt{int \funnm{sigsuspend}(const sigset\_t *\emph{sigmask});} |
| 604 | +]]]) |
583 | 605 | \begin{itemize} |
584 | 606 | \item like \funnm{pause}(), also temporarily changes the blocked signal mask |
585 | 607 | \end{itemize} |
| 608 | +ifdef([[[NOSPELLCHECK]]], [[[ |
586 | 609 | \texttt{int \funnm{sigwait}(const sigset\_t *\emph{set}, int *\emph{sig});} |
| 610 | +]]]) |
587 | 611 | \begin{itemize} |
588 | 612 | \item waits for a signal from \emph{set} (must be blocked) and puts the signal |
589 | | -number to \emph{sig}. |
| 613 | +number to \emph{\texttt{sig}}. |
590 | 614 | \item the signal handler is not called |
591 | 615 | \end{itemize} |
592 | 616 | \end{slide} |
|
0 commit comments