90 likes | 212 Views
Process Management. Process Fundamentals. All program that has started execution is a process. Every process in Linux has a PID. It also has UID and GID associated with it. All process are subject to the Linux scheduler. It controls a process’s priority.
E N D
Process Fundamentals All program that has started execution is a process. Every process in Linux has a PID. It also has UID and GID associated with it. All process are subject to the Linux scheduler. It controls a process’s priority. The ‘ps’command can be used to examine all currently running processes. The ‘top’command can be used to monitor all running processes.
More fundamentals The very first process of a Linux system when it boots up will be /sbin/init. All other process are spawn off this initial one. We can examine a process ancestry using the ‘pstree’ command. Processes can always be found in one of five well defined states: runnable, voluntarily sleeping, involuntarily sleeping, stopped, or zombie. When a process dies, it is the responsibility of the process's parent to collect it's return code and resource usage information. When a parent dies before it's children, the orphaned children are inherited by the first process (usually /sbin/init).
Process scheduling Every process has a priority value. This value ranges -20 to +19 All user started processes have a default priority value of zero 0. The smaller the value, the more priority a process receives from the scheduler. We can change a process’s priority suing ‘nice’ or ‘renice’ commands. For normal users, we can increase the priority value of a process. That means, we cannot make it more negative than it presently is.
Signals Signals are Inter-process Communications. Usually we make use of them to control the state of a process. There are many process signals, but we only need to know 2 of them. SIGTERM(15) and SIGKILL(9). Sending SIGTERM request causes a process to terminate. Sending SIGKILL causes a process to stop immediately. The kill command sends signals to other processes.
Job control The bash shell allows commands to be run in the background as "jobs". The bash shell allows one job to run in the foreground, and can have multiple backgrounded jobs. The jobs command will list all backgrounded jobs. The CTRL-Z key sequence will suspend and background the current foreground job. The bg command resumes a backgrounded job. The fg command brings a backgrounded job to the foreground.
Delayed Tasks Using the ‘at’ command. We can delay the execution of a command to a later time. Output from standard out of these delayed processes will redirected as an email to the user account by the system. atq and atrm are used to examine and remove currently scheduled jobs.
Recurring tasks • Use ‘crontab –e’ to create a crontab file. This file contains all recurring tasks that a user needs to be automated. • Standard output from these processes will be emailed to the user. • Uses 5 fields to specify timing information. • Minute, hour, day of the month, month, day of the week, command. • All fields separated by spaces.