Professional Documents
Culture Documents
Chris Kuehl
Who am I? ckuehl@ocf.berkeley.edu
????
Zombie processes
When a process exits, it
temporarily becomes a zombie:
● No longer running
● Totally normal!
What happens when a
process dies? Processes always exit with
an “exit code” (int between
pid_t result = fork(); 0 and 255)
if (result > 0) {
/* parent process */ Typically, 0 is success,
sleep(100); anything else is an error
} else if (result == 0) {
/* child process */
exit(123);
} else { /* error */ }
Parents need to wait() on children
(aka reap)
pid_t result = fork(); Process tree after start:
if (result > 0) {
/* parent process */
int status;
wait(&status);
printf("%d\n", WEXITSTATUS(status));
} else if (result == 0) { After 10 seconds:
/* child process */
sleep(10);
exit(123); Prints out:
} else { /* error */ }
What if the parent exits first?
pid_t result = fork();
Process tree after start:
if (result > 0) {
/* parent process */
parent
sleep(1);
child
exit(0);
} else if (result == 0) { After 1 second:
/* child process */
sleep(10);
child
exit(123);
} else { /* error */ }
Orphaned processes are
re-parented under PID 1
Process signaling
Simple messages to other processes.
(pgrep is
especially useful
for composing)
Working with processes: htop
(makes pretty screenshots)
CHAPTER TWO
Init systems & services
What is an init system?
The first process launched (PID 1), lives forever
Core responsibilities:
● Launching enough processes to make the
system useful
● Reap orphaned zombie processes
What does a bare-bones init
system look like?
/bin/bash can work in a pinch
exec /usr/bin/my-cool-server
Modern init system: systemd
Originally comes from Fedora-land
Dependency-based
Parallel start and stop
Way easier to write than traditional init scripts
Modern init system: systemd
Goals:
● Unify core Linux tooling across distributions
● Provide excellent UX
Ended up reimplementing syslog, cron,
networking, GRUB, ConsoleKit, udev
Turns out they’re controversial
In practice, systemd has won
...
systemctl status
systemctl start/stop
systemctl enable/disable
systemctl (no arguments)
journalctl
View recent logs from a unit:
journalctl -u $unit -e
[Service]
ExecStart=/usr/bin/my-cool-service
[Install]
WantedBy=multi-user.target
Conclusion (i.e. opinions)
● Think about the UNIX philosophy as a guiding
principle, not a law
decal.ocf.berkeley.edu/signin
Week 6: Engelbart