If you suspect your UNIX computer is haunted or possessed, you may feel vindicated to know that it is, in fact, harbouring both zombies and daemons. As if that were not enough, it is also known to occasionally produce orphans. Yet, despite this apparent wasteland of the undead, spirits, and parentless children, UNIX is actually a pleasant place: daemons are benign and hardworking; zombies are not troublesome and consume minimal resources; and orphans are immediately adopted by a powerful process.

UNIX daemons are processes which are perhaps best considered as intelligent, invisible servants. They are similar to other user processes, except they don't exit when their initial task is complete, but instead wait for more work. Most daemons are initiated when the computer starts and persist until it shuts down. They are background processes, doing their work transparently, without direct user interaction, which is why users seldom hear of them. As an illustration, consider a hypothetical daemon called printemd (pronounced "print'em D") which controls file printing. printemd starts when the computer boots and runs under an account specifically customized for it which I'll call the "print" account. It immediately looks for files in a special directory. If it finds any, it sequentially copies these to a printer then deletes them. It then periodically checks this directory for new files and likewise prints and deletes these. Users submit print jobs with the command printem which simply copies the desired files to the daemon's directory, then returns control to the user. Printing is controlled by the system administrator through the commands stopem and startem. stopem is used to temporarily disable printing by sending a signal to printemd (signals are a standard UNIX Inter-Process Communication service or IPC). Upon receipt of this signal the daemon finishes its current copy, then waits for a signal from startem before resuming printing. Printer access is restricted to processes running under the "print" account, ensuring printem's exclusive control of printing. An alternative to printemd might be for each printem process to directly copy files to the printer. Recall, however, that UNIX is a multi-process, multi-user system with processes operating in an interleaved or parallel fashion. If multiple printem processes were to run simultaneously their files could become interleaved on the printer. If synchronization IPCs were used to prevent this, each user would still have to wait for all other printem processes to finish, in addition to their own, before regaining control of their terminals. As well, all user processes would need printer access, opening the door to malicious or accidental corruption of printed files. While printer security may seem trivial in a seismic processing environment, consider a company which prints cheques from a UNIX computer. Though simple, this example illustrates the ease with which a daemon can enforce serial access, quickly return control to the user, and prevent corruption of printed files.

Consider another hypothetical daemon which is not concerned about serialization but rather with rapid response time. Since this is loosely modelled on daemons which provide World Wide Web (WWW or Web) services, I'll call it webd. webd is started manually by a user and waits for requests to arrive through an Internet socket, an IPC facility which provides two way communication between processes on the same computer, or on different computers connected with a network. When a request arrives, webd makes a child process (or just "child" for short) to service it, then waits for another request. This ensures a rapid initial response to each request even though the total time to complete it may be increased through competition among the daemon's children. On a multiple CPU computer the children's work can be shared among the CPUs, increasing performance. The processes making requests are typically interactive Web browsers. These ask for data representing such things as text, images, videos or sound. These data are acquired by the daemon's children and sent over the socket to the browser which then displays or plays them on the user's computer.

These examples illustrate the basic client-server relationship between processes which request actions (clients) and daemon processes which carry them out (servers). Daemons are fundamental to UNIX, being used extensively to provide services such as e-mail, remote login, remote file transfer, Web browsing, application licensing, printing, system error logging, temporary file cleanup, and graphical windowing systems. Daemons can be a major source of a special type of process known as a zombie. A zombie results when a child terminates before its parent, leaving a small amount of information for it. The kernel retains the child in its process table, with a zombie status, until the parent requests this information, or terminates (skeptics can read the ps(1) man page). Zombies consume no resources other than a small amount of the kernel's memory. This is generally harmless except in the case of poorly written user daemons which don't collect their children's statuses often enough. This can cause the kernel's process table to fill up, preventing the generation of new processes and effectively making the computer unusable.

Orphans are the converse of zombies. When a process's parent terminates, its children become orphans. Because every user process must have a parent, the special system process init, which is always present, immediately adopts all orphans. In practice, well written daemons voluntarily become orphans in order to ensure their autonomy, which is why ps(1) shows their parent to be init.

Daemons, zombies and orphans are fundamental to UNIX's operation. They provide transparent and efficient services to users and generally keep a clean house. They can't be blamed for that foreboding sense that overcomes some whenever they approach a computer.

Daemons, zombies and orphans are fundamental to UNIX's operation. They provide transparent and efficient services to users and generally keep a clean house. They can't be blamed for that foreboding sense that overcomes some whenever they approach a computer.



Share This Column