Booting Process
Booting Process
Booting Process
asynchronously, and the output of one process goes to the input of the other
process. The parent shell meanwhile waits for its child process (we) to exit, then
proceeds as usual: The entire command line completes when wc exits. The shell
loops and reads the next command.
.,
• This is an infinite loop; process 0 usually sleeps in the
• loop unless there is work for it to do.
kernel, but that would be more complicated than the implementation just described.
To follow the latter procedure, exec would have to parse file names in kernel space,
not just in user space, as in the current implementation. Such generality, needed
only for init, would complicate the exec code and slow its performance in more
common cases.
The init process (Figure 7.31) is a process dispatcher, spawning processes that
allow users to log in to the system, among others. Init reads the file "/etc/inittab"
for instructions about which processes to spawn. The file "/etc/inittab" contains
lines that contain an "id," a state identifier (single user, multi-user, etc'), an
"action" (see exercise 7.43), and a program specification (see Figure 7.32). lnit
reads the file and, if the state in which it was invoked matches the state identifier
of a line, creates a process that executes the given program specification. For
example, when invoking init for the multi-user state (state 2), init typically spawns
7.9 SYSTEM BOOT AND THE (NIT PROCESS 237
{
execl ("process specified in buffer");
exitO;
*'
,. init process does not wait .,
,. loop back to while
getty processes to monitor the terminal lines configured on a system. When a user
successfully logs in, getty goes through a login procedure and execs a login shell,
described in Chapter 10. Meanwhile, init executes the wait system call, monitoring
the death of its child processes and the death of processes "orphaned" by exiting
parents.
Processes in the UNIX system are either user processes, daemon processes, or
kernel processes. Most processes on typical systems are user processes, associated
with users at a terminal. Daemon processes are not associated with any users but
do system-wide functions, such as administration and control of networks, execution
of time-dependent activities. line printer spooling, and so on. lnit may spawn
daemon processes that exist throughout the lifetime of the system or, on occasion,
users may spawn them. They are like user processes in that they run at user mode
and make system calls to access system services.
Kernel processes execute only in kernel mode. Process 0 spawns kernel
processes, such as the page-reclaiming process vhand, and then becomes the
swapper process. Kernel processes are similar to daemon processes in that they
provide system-wide services, but they have greater control over their execution
priorities since their code is part of the kernel. They can access kernel algorithms
and data structures directly without the use of system calls, so they are extremely
powerful. However, they are not as flexible as daemon processes, because the
kernel must be recompiled to change them.
7.10 SUMMARY
This chapter has discussed the system calls that manipulate the process context and
control its execution. The fork system call creates a new process by duplicating all
the regions attached to the parent process. The tricky part of the fork
implementation is to initialize the saved register context of the child process, so that
it starts executing inside the fork system call and recognizes that it is the child
process. All processes terminate in a call to the exit system call, which detaches
the regions of a process and sends a "death of child" signal to its parent. A parent
process can synchronize execution with the termination of a child process with the
wait system call. The exec system call allows a process to invoke other programs,
overlaying its address space with the contents of an executable file. The kernel
detaches the old process regions and allocates new regions, corresponding to the
executable file. Shared-text files and use of the sticky-bit mode improve memory
utilization and the startup time of execed programs. The system allows ordinary
users to execute with the privileges of other users, possibly superuser, with setuid
programs and use of the setuid system call. The brk system call allows a process to
change the size of its data region. Processes control their reaction to signals with
the signal system call. When they catch a signal, the kernel changes the user stack
and the user saved register context to set up the call to the signal handler.
Processes can send signals with the kill system call, and they can control receipt of
signals designated for particular process groups through the setpgrp system call.