Lesson 2 | Types of processes |
Objective | Define the two main types of processes on a UNIX system |
Types of Processes
A UNIX
process is a running program. All the useful work done on the system is done by one sort of process or another. Processes come in various flavors. Some processes hide in the background, carrying out infrastructure duties such as running print queues. Others, such as
shell[1] programs, interact with humans. Stil others are started and stopped by user commands, and carry out specific tasks to serve users.
Interactive Processes
One important class of processes is the class of interactive processes. These are the processes that take input and generate output in
response to direct human interaction. Probably the most important type of interactive process is a shell program. Shell programs, such
as the Bourne Shell (/bin/sh), the Korn Shell (/bin/ksh), and the Bourne Again Shell (/bin/bash) are interactive processes that take
input from a terminal and execute user commands. Each time a user logs on, the login process starts a new login shell process for that
user. When the login shell terminates, the user is logged out. Many commands also give rise to interactive processes. For example, the
grep[2] command starts a grep process, which reads some specified list of files and generates output for human use. Similarly, the
ls
command produces an ls process, which reads directories on disk and generates human-readable output. In general, interactive processes are associated with a terminal
device[3], on which they may display their output and collect their
input.
Purpose of daemons on Unix System
In a Unix-based system, daemons are background processes that perform vital tasks to facilitate and streamline the operation of the system. They are the unsung heroes of Unix systems, quietly performing their duties behind the scenes to ensure smooth running of the system.
The term 'daemon' was inspired by Greek mythology, where daemons were benevolent spirits who worked behind the scenes to ensure the world's efficient operation. Similarly, in Unix systems, daemons are typically initiated during system startup and quietly perform their tasks without direct user interaction.
Daemons serve a myriad of functions, including:
- Network Services: Many daemons are responsible for handling network requests. For instance, the HTTPD daemon is used to serve web pages, while the SSHD daemon allows for secure remote logins.
- Device and Resource Management: Some daemons manage system resources and peripherals. The LPD daemon, for example, manages print jobs, while the CROND daemon schedules and executes background tasks at specific times.
- Logging and Monitoring: Daemons like SYSLOGD and RSYNCD handle system logging, monitoring system events, and synchronizing files between systems, providing vital information for troubleshooting and performance optimization.
- System Maintenance: Some daemons help maintain the system, performing tasks such as cleaning up temporary directories (TMPWATCH), updating databases of file names (UPDATEDB), or rotating and archiving log files (LOGROTATE).
Daemons usually operate invisibly in the background. However, they generate log files that can be inspected if necessary, for troubleshooting purposes or for regular system audits. Daemon processes typically have 'd' appended to their names (e.g., HTTPD, SSHD) to indicate their nature. While daemons are essential to a Unix system, they also represent potential points of vulnerability. Each daemon running on a system opens a new potential avenue for system compromise. Therefore, prudent system administration involves running only necessary daemons and ensuring they are kept updated to mitigate potential security threats. In conclusion, daemons in a Unix system serve as the workhorses, performing a myriad of tasks that allow for the smooth and efficient operation of the system. They are an integral component of the system's architecture, providing vital network services, managing devices and resources, logging and monitoring system activity, and maintaining the system's health.
Process lurking in background
Many processes on a running UNIX system lurk in the background, unconnected to any terminal and generating no visible input or output. These processes are called daemons. A daemon is a process that is not associated with any terminal and is dedicated to
handling a particular task. For example, daemon processes run the print queue and handle network infrastructure tasks. On systems
supporting a Web server, the Web server process itself is usually a daemon. Keeping daemons correctly configured and running properly
is an important element of UNIX system administration.
Files versus Processes
Programs are stored in files; therefore, every program has an associated file. For example, the grep
command is a program
stored in the file /usr/bin/grep. As mentioned earlier, running the grep
command starts a grep process. It is important to
keep straight the distinction between the file /usr/bin/grep and a running grep process. A process is a running program. Because UNIX is multitasking, a given program may be run more than once simultaneously. Each separate
invocation of the program gives rise to a new process, even though all these processes came from the same file.
[1]shell: The shell is a program that interprets your commands and passes them to the operating system for further processing. You enter commands at the shell prompt (also called the system prompt or command prompt).
[2]grep: The grep command searches the named input files for lines containing a match to the given pattern. By default, grep prints the matching lines. The grep command reads from standard input if no files are given or when a filename of - is encountered.
[3]device: A device is a piece of hardware used by the system, such as hard drives, CD-ROMs, and so on. Devices are treated as a special type of file.