Unix processes

Here are some point-form-like notes about what I am saying about unix processes. This page contains a list of topics and links into example code.

This material is covered fairly thoroughly in Haviland et al chapter 5, some of 6, and the earlier parts of 7.


most things are files (e.g. disks, printers); what aren't are processes.

ps ax

Your shell is a process, everything you run is a process.
"init" is the great ancestor process, pid 1.
"init" makes a getty for each line; getty says hi, sets up the terminal, and runs login.
Login checks your password, runs shell; shell asks you for commands to run and runs them.

Primitives: fork, exec, wait.
fork-exec-wait idiom. (use C library function system(); don't "re-invent the wheel".)

(This example is deficient in that it should check if fork()'s return value is negative indicating error; this check is omitted here for simplicity but is illustrated in an example below.)


Processes have characteristics:
pid, ruid, euid, ppid;
current working directory, umask (not discussed), list of open files (file descriptors),
argv, environment.

Be aware of the "ps" command.
ps ax

other primitives: open, close, dup, pipe.

How to implement "cmd >file"
(except that it should check if fork()'s return value is negative indicating error; this check is illustrated in the next example)

how to implement "cmd1 | cmd2"

signals. kill command.
[example signal code written in lecture]
(see Haviland et al chapter 6)


The kernel is   "the only unix code that cannot be substituted by a user to their own liking"

Therefore, minimal.

System calls available from high-level languages via "glue routines".
What's not in the kernel is in the C library; seems the same to the user (programmer) except that it is substitutable. Example: system().


[list of topics covered]
[course notes available so far]
[main course page]