Process: (essentially) a running program
In Posix-like systems, a new process is created by fork(2)
system call
New program can replace current program in existing process using exec*
(sloppy: one system call, several library wrappers) callls
exec
is successful, it does not return (because the process is running a new program)exec
could fail for several reasons; most common is the
replacement program file does not exist or is not executableSeparation of program initiation & process creation was a design choice
fork
before exec
(e.g. reopen fd 0, 1, 2)fork
for divide & conquerOpen files stay open across fork
, exec
Program termination: parent process collects child exit status using wait(2)
or waitpid(2)
wait(2)
is misnamed (shrug)Z
(zombie)
init
(process #1) adopts orphans (init
reaps orphan zombies)Pipes: producer-consumer model
pipe(2)
system call
int
to hold file descriptors
fork
/exec
popen(3)
(C standard library function) only slightly related to pipe(2)
FILE*
object that wraps the pipe file descriptorsystem(3)
but allows parent process to collect outputFile & pipe descriptors use same read
/write
system calls
Everything is a file: devices, pseudo devices, network connections
System calls to determine nature of open file (regular/device/etc.)
ioctl(2)
(generalized interface)Shell does string processing to determine which program(s) to run, argv
(argument vector), file descriptors 0, 1, 2
Shell syntax: redirect input/outpu
<
(input)>
(output)>>
(append output)2>
(standard error)|
(pipe output of first to input of second--restricted use of pipe(2)
capabilities)Pipelines: data-flow style
Assigment 1: convex hull
software analog of hardware interrupts
signal is small integer with system-defined semantics
C header file defines symbolic names: man 7 signal
SIGUSR1
10: user-definedSIGUSR2
12: user-definedSIGHUP
1: hangupSIGINT
2: keyboard interrupt (control-C)SIGSEGV
11: segmentation violationSIGALRM
14: timerSIGCHLD
17: child process stopped/terminateddefault action depends on specific signal
SIGCONT
)SIGSTOP
/SIGTSTP
)process control block: signal dispatch table
signal(2)
: system call to specific action on signal
sigaction(2)
action:
SIG_DFL
: default behavior (for this signal)SIG_IGN
: ignore signalSIGKILL
(9): terminate program
signal may be due to event (e.g. program executes illegal instruction, child process terminates) or explicitly sent (by another process)
kill(2)
: send signal
kill(2)
sends signal, does not kill program
SIG_DFL
) is to self-terminatekill(1)
: thin wrapper program around kill(2)
to dispatch signal, kernel manipulates the process's kernel data structure(s) while the process is not running
cooperating processes
already discussed some ways for processses to commmunicate:
wait(2)
(or variant)executable file (on disk): passive data
#include <elf.h>
man 5 elf
running process
argv
/envp
kernel view of process: data structure (process control block)
nice
value: only root (superuser/admin) may hae negative nicenessprocess status
scheduler selects ready process and runs it until
scheduling refinements
2 basic paradigms for communication
named pipes
Unix-domain sockets
networking