SlideShare a Scribd company logo
Process Management
Overview
• Each task in Unix starts a process.
• Each process is assigned a unique process identification
number (PID).
• Some processes are started by the system and are used
to control activities, these are usually called daemons
• Processes started by the user from the shell inherit the
shell’s terminal, and interact through it
• Processes started in the GUI don’t usually have a
terminal associated with them
Processes and PIDs
• Use the ‘ps’ command to list the processes currently
running on the system.
• The command is:
ps [options]
• Commonest options are -ef: (in some UNIXs aux)
– –e Every process on the system
– –f Full listing
• Use pgrep command to search for a specific process.
This is equivalent to ps –ef | grep
• Without options, ps will just print all processes that share
the terminal with it.
Processes and PIDs
• ‘ps’ can also print out resource usage information for all
processes on the system.
Example
$ ps aux | head
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.0 0.0 10348 732 ? Ss 2010 0:04 init [3]
apache 6019 0.0 0.8 241120 9184 ? S Jun26 0:01 /usr/sbin/httpd
root 6108 0.0 0.0 5908 620 ? Ss Mar30 0:16 syslogd -m 0
Process Life Line
• There are three stages in the process life cycle:
– Fork – the parent process creates an exact image of
itself in the memory and gets a new PID.
– Exec – the new process rewrites its image in the
memory and executes. The parent (i.e. shell) either
waits for the process to finish (foreground) or
continues to run (background)
– Termination – the child process returns a signal to the
parent, which contains an exit code. The parent
process deletes the child from the process table.
Signals
• UNIX systems use signals to communicate different
scenarios between processes
• The kernel manages signal transfers
• When a process receives a signal it stops its current
activity and moves to a signal handling routine
• Different signals have different default routines, which
can be overridden by the programmer
• Among other things signals terminate, suspend and
continue process.
• From a regular user perspective, most signals are
irrelevant – they are used by the kernel
Signaling with kill
• Use the command kill to send a signal to a process.
$ kill [-signal] %job-id|process-id
• The name is derived from the fact the default signal kill
sends is the SIGTERM (15) signal, which by default
terminates the process
• For a foreground process, ^C achieves the same result,
but it is actually the terminal sending a SIGINT (2) to the
process
• Both these signals can be blocked by the process (the
BASH, for example, blocks them)
• The signal SIGKILL (9) cannot be blocked, so if all else
fails, this is the way to destroy a stuck process
• ^Z sends the signal SIGTSTP, while SIGSTOP
is a non blocked equivalent
Cron
• The cron daemon continually checks the users crontab
files and execute periodic tasks
• Edit the user’s crontab with the command crontab –e
• An editor (usually vi) is opened with the crontab. The
table has six fields:
minute,hour,day,month,weekday,command
59,23,*,*,*, echo Hello > hello.$(date +%s)
• You can list your crontab with crontab –l
• In the system level, there is an additional mechanism of
crontabs for once-a-day, once-a-week, etc.
Monitoring processes by top
• ‘top’ - Displays the top processes on the system and
periodically updates the information.
• The first few lines of the display show general
information about the system’s state:
– Load averages in the last 1, 5, and 15 minutes.
– Existing processes no. and the no. of processes in
each state (sleeping, waiting, running, starting,
zombie, and stopped).
– Percentage of time spent in each of the processor
states (user, nice, system, idle, interrupt and
swapper) per processor on the system.
– Average value for each of the processor states (only
on multi-processor systems).
Monitoring processes by top – cont.
CPU Processor number on which the process is executing (only on multi-processor systems).
TTY Terminal interface used by the process
PID Process ID number
USERNAME Name of the owner of the process
PRI Current priority of the process
NI Nice value ranging from -20 to +20
SIZE Total size of the process in kilobytes.
RES Resident size of the process in kilobytes
STATE Current state of the process. The various states are sleep, wait, run, idle, zomb, or stop
TIME Number of system and CPU seconds the process has consumed
%WCPU Weighted CPU (central processing unit) percentage
%CPU Raw CPU percentage. This field is used to sort the top processes
COMMAND Name of the command the process is currently running

More Related Content

PPTX
Operating Systems - Processor Management
ODP
Linux monitoring
PDF
Process management
PPTX
Computer Architecture - Program Execution
PPT
水晶礦脈
PPTX
Smarter Scheduling (Priorities, Preemptive Priority Scheduling, Lottery and S...
PPTX
CPU Non-Preemptive Scheduling
PPT
rtos by mohit
Operating Systems - Processor Management
Linux monitoring
Process management
Computer Architecture - Program Execution
水晶礦脈
Smarter Scheduling (Priorities, Preemptive Priority Scheduling, Lottery and S...
CPU Non-Preemptive Scheduling
rtos by mohit

What's hot (20)

PPT
Priority scheduling algorithms
PPTX
Program execution
PPTX
Process Control Block & Threads and Their Management
PPTX
Introduction to Scheduling
PPTX
OPERATING SYSTEM-"Scheduling policies"
PPT
Microprogram Control
PPTX
Presentiaon task sheduling first come first serve FCFS
PPTX
Computer architecture control unit
PDF
Linux System Monitoring basic commands
PPT
Microarchitecture
PPTX
Microprogrammed Control Unit
PPTX
Register Organization and Instruction cycle
PPTX
Os presentation process
PPT
Ch7 official
PPT
Cpu scheduling algorithms simulation using java
PPTX
Micro Programmed Control Unit
PPTX
3 4- computer organization and archietecture- COA- CO- Computer organization
PPTX
Operating system - Process and its concepts
PPTX
CPU Scheduling Algorithms
PPTX
PPT CPU
Priority scheduling algorithms
Program execution
Process Control Block & Threads and Their Management
Introduction to Scheduling
OPERATING SYSTEM-"Scheduling policies"
Microprogram Control
Presentiaon task sheduling first come first serve FCFS
Computer architecture control unit
Linux System Monitoring basic commands
Microarchitecture
Microprogrammed Control Unit
Register Organization and Instruction cycle
Os presentation process
Ch7 official
Cpu scheduling algorithms simulation using java
Micro Programmed Control Unit
3 4- computer organization and archietecture- COA- CO- Computer organization
Operating system - Process and its concepts
CPU Scheduling Algorithms
PPT CPU
Ad

Viewers also liked (7)

ODP
Augusta Linux User Group - Vim Introduction
PPTX
Infra / Cont delivery - 3rd party automation
PDF
Unit3 browsing the filesystem
PPTX
14 network tools
PPT
03 browsing the filesystem
ODP
Linux Internals - Kernel/Core
ODP
chroot and SELinux
Augusta Linux User Group - Vim Introduction
Infra / Cont delivery - 3rd party automation
Unit3 browsing the filesystem
14 network tools
03 browsing the filesystem
Linux Internals - Kernel/Core
chroot and SELinux
Ad

Similar to 13 process management (20)

PPTX
UNIX Notes
PPTX
Advanced Operating Systems......Process Management
PPTX
AOS_Module_4ssssssssssssssssssssssss.pptx
PDF
Unit 1.1.pdfOperating_SystemOperating_System
PDF
Operating System Structure Part-I.pdf
PPTX
Operating Systems
DOCX
LP-Unit3.docx
PPTX
Computer system architecture
PDF
Linux Internals - Part II
PDF
OS - Process Concepts
PPT
Chapter 2 (Part 2)
PPTX
07 Systems Software Programming-IPC-Signals.pptx
PPT
Operating System 3
PPTX
Operating Systems Process Management.pptx
PDF
Course 102: Lecture 19: Using Signals
PDF
Bedtime Stories on Operating Systems.pdf
PDF
Ch3 processes
PPTX
operating system process management with example
PDF
Linux : Booting and runlevels
PDF
process.pdfzljwiyrouyaeutoaetodtusiokklhh
UNIX Notes
Advanced Operating Systems......Process Management
AOS_Module_4ssssssssssssssssssssssss.pptx
Unit 1.1.pdfOperating_SystemOperating_System
Operating System Structure Part-I.pdf
Operating Systems
LP-Unit3.docx
Computer system architecture
Linux Internals - Part II
OS - Process Concepts
Chapter 2 (Part 2)
07 Systems Software Programming-IPC-Signals.pptx
Operating System 3
Operating Systems Process Management.pptx
Course 102: Lecture 19: Using Signals
Bedtime Stories on Operating Systems.pdf
Ch3 processes
operating system process management with example
Linux : Booting and runlevels
process.pdfzljwiyrouyaeutoaetodtusiokklhh

More from Shay Cohen (14)

PPT
Linux Performance Tunning Memory
PPT
Linux Performance Tunning Kernel
PPT
Linux Performance Tunning introduction
PPTX
12 linux archiving tools
PPTX
11 linux filesystem copy
PPTX
10 finding files
PPT
08 text processing_tools
PPT
07 vi text_editor
PPT
06 users groups_and_permissions
PPT
05 standard io_and_pipes
PPT
04 using and_configuring_bash
PPT
02 linux desktop usage
PPT
09 string processing_with_regex copy
PPT
01 linux history overview
Linux Performance Tunning Memory
Linux Performance Tunning Kernel
Linux Performance Tunning introduction
12 linux archiving tools
11 linux filesystem copy
10 finding files
08 text processing_tools
07 vi text_editor
06 users groups_and_permissions
05 standard io_and_pipes
04 using and_configuring_bash
02 linux desktop usage
09 string processing_with_regex copy
01 linux history overview

Recently uploaded (20)

PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Heart disease approach using modified random forest and particle swarm optimi...
PDF
WOOl fibre morphology and structure.pdf for textiles
PDF
Web App vs Mobile App What Should You Build First.pdf
PPTX
TLE Review Electricity (Electricity).pptx
PDF
August Patch Tuesday
PDF
Microsoft Solutions Partner Drive Digital Transformation with D365.pdf
PDF
Accuracy of neural networks in brain wave diagnosis of schizophrenia
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Getting Started with Data Integration: FME Form 101
PDF
project resource management chapter-09.pdf
PDF
A comparative analysis of optical character recognition models for extracting...
PPTX
Tartificialntelligence_presentation.pptx
PDF
ENT215_Completing-a-large-scale-migration-and-modernization-with-AWS.pdf
PDF
1 - Historical Antecedents, Social Consideration.pdf
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Assigned Numbers - 2025 - Bluetooth® Document
PDF
Encapsulation theory and applications.pdf
PPTX
Group 1 Presentation -Planning and Decision Making .pptx
PDF
DP Operators-handbook-extract for the Mautical Institute
Building Integrated photovoltaic BIPV_UPV.pdf
Heart disease approach using modified random forest and particle swarm optimi...
WOOl fibre morphology and structure.pdf for textiles
Web App vs Mobile App What Should You Build First.pdf
TLE Review Electricity (Electricity).pptx
August Patch Tuesday
Microsoft Solutions Partner Drive Digital Transformation with D365.pdf
Accuracy of neural networks in brain wave diagnosis of schizophrenia
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Getting Started with Data Integration: FME Form 101
project resource management chapter-09.pdf
A comparative analysis of optical character recognition models for extracting...
Tartificialntelligence_presentation.pptx
ENT215_Completing-a-large-scale-migration-and-modernization-with-AWS.pdf
1 - Historical Antecedents, Social Consideration.pdf
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Assigned Numbers - 2025 - Bluetooth® Document
Encapsulation theory and applications.pdf
Group 1 Presentation -Planning and Decision Making .pptx
DP Operators-handbook-extract for the Mautical Institute

13 process management

  • 2. Overview • Each task in Unix starts a process. • Each process is assigned a unique process identification number (PID). • Some processes are started by the system and are used to control activities, these are usually called daemons • Processes started by the user from the shell inherit the shell’s terminal, and interact through it • Processes started in the GUI don’t usually have a terminal associated with them
  • 3. Processes and PIDs • Use the ‘ps’ command to list the processes currently running on the system. • The command is: ps [options] • Commonest options are -ef: (in some UNIXs aux) – –e Every process on the system – –f Full listing • Use pgrep command to search for a specific process. This is equivalent to ps –ef | grep • Without options, ps will just print all processes that share the terminal with it.
  • 4. Processes and PIDs • ‘ps’ can also print out resource usage information for all processes on the system. Example $ ps aux | head USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND root 1 0.0 0.0 10348 732 ? Ss 2010 0:04 init [3] apache 6019 0.0 0.8 241120 9184 ? S Jun26 0:01 /usr/sbin/httpd root 6108 0.0 0.0 5908 620 ? Ss Mar30 0:16 syslogd -m 0
  • 5. Process Life Line • There are three stages in the process life cycle: – Fork – the parent process creates an exact image of itself in the memory and gets a new PID. – Exec – the new process rewrites its image in the memory and executes. The parent (i.e. shell) either waits for the process to finish (foreground) or continues to run (background) – Termination – the child process returns a signal to the parent, which contains an exit code. The parent process deletes the child from the process table.
  • 6. Signals • UNIX systems use signals to communicate different scenarios between processes • The kernel manages signal transfers • When a process receives a signal it stops its current activity and moves to a signal handling routine • Different signals have different default routines, which can be overridden by the programmer • Among other things signals terminate, suspend and continue process. • From a regular user perspective, most signals are irrelevant – they are used by the kernel
  • 7. Signaling with kill • Use the command kill to send a signal to a process. $ kill [-signal] %job-id|process-id • The name is derived from the fact the default signal kill sends is the SIGTERM (15) signal, which by default terminates the process • For a foreground process, ^C achieves the same result, but it is actually the terminal sending a SIGINT (2) to the process • Both these signals can be blocked by the process (the BASH, for example, blocks them) • The signal SIGKILL (9) cannot be blocked, so if all else fails, this is the way to destroy a stuck process • ^Z sends the signal SIGTSTP, while SIGSTOP is a non blocked equivalent
  • 8. Cron • The cron daemon continually checks the users crontab files and execute periodic tasks • Edit the user’s crontab with the command crontab –e • An editor (usually vi) is opened with the crontab. The table has six fields: minute,hour,day,month,weekday,command 59,23,*,*,*, echo Hello > hello.$(date +%s) • You can list your crontab with crontab –l • In the system level, there is an additional mechanism of crontabs for once-a-day, once-a-week, etc.
  • 9. Monitoring processes by top • ‘top’ - Displays the top processes on the system and periodically updates the information. • The first few lines of the display show general information about the system’s state: – Load averages in the last 1, 5, and 15 minutes. – Existing processes no. and the no. of processes in each state (sleeping, waiting, running, starting, zombie, and stopped). – Percentage of time spent in each of the processor states (user, nice, system, idle, interrupt and swapper) per processor on the system. – Average value for each of the processor states (only on multi-processor systems).
  • 10. Monitoring processes by top – cont. CPU Processor number on which the process is executing (only on multi-processor systems). TTY Terminal interface used by the process PID Process ID number USERNAME Name of the owner of the process PRI Current priority of the process NI Nice value ranging from -20 to +20 SIZE Total size of the process in kilobytes. RES Resident size of the process in kilobytes STATE Current state of the process. The various states are sleep, wait, run, idle, zomb, or stop TIME Number of system and CPU seconds the process has consumed %WCPU Weighted CPU (central processing unit) percentage %CPU Raw CPU percentage. This field is used to sort the top processes COMMAND Name of the command the process is currently running

Editor's Notes

  • #3: Each task you perform in the Unix environment starts a process. An example of a process is using vi to edit a text file, or sending file to a printer. Each process is assigned a unique process identification number (PID), which is used by the system to identify the process.The following chapter defines useful commands to handle processes.
  • #4: Example:$ ps –ef | more UID PID PPID C STIME TTY TIME CMDroot 0 0 0 Dec 19 ? 0:01 sched root 1 0 0 Dec 19 ? 0:11 /etc/init - root 2 0 0 Dec 19 ? 0:00 pageout root 3 0 0 Dec 19 ? 201:03 fsflush root 126 1 0 Dec 19 ? 0:00 /usr/lib/netsvc/yp/ypxfrd root 322 1 0 Dec 19 ? 0:00 /usr/lib/saf/sac -t 300root 104 1 0 Dec 19 ? 2:34 /usr/sbin/rpcbind root 118 116 0 Dec 19 ? 1:01 rpc.nisd_resolv -F -C 8 -p 1073741824 -t udp root 106 1 0 Dec 19 ? 0:00 /usr/sbin/keyservroot 304 1 0 Dec 19 ? 0:00 /usr/sbin/rpld -a root 116 1 0 Dec 19 ? 7:46 /usr/lib/netsvc/yp/ypserv -d root 123 1 0 Dec 19 ? 0:03 /usr/lib/netsvc/yp/ypbind root 133 1 0 Dec 19 ? 0:00 /usr/lib/netsvc/yp/rpc.ypupdated--More— 
  • #5: Example:$ ps –ef | more UID PID PPID C STIME TTY TIME CMDroot 0 0 0 Dec 19 ? 0:01 sched root 1 0 0 Dec 19 ? 0:11 /etc/init - root 2 0 0 Dec 19 ? 0:00 pageout root 3 0 0 Dec 19 ? 201:03 fsflush root 126 1 0 Dec 19 ? 0:00 /usr/lib/netsvc/yp/ypxfrd root 322 1 0 Dec 19 ? 0:00 /usr/lib/saf/sac -t 300root 104 1 0 Dec 19 ? 2:34 /usr/sbin/rpcbind root 118 116 0 Dec 19 ? 1:01 rpc.nisd_resolv -F -C 8 -p 1073741824 -t udp root 106 1 0 Dec 19 ? 0:00 /usr/sbin/keyservroot 304 1 0 Dec 19 ? 0:00 /usr/sbin/rpld -a root 116 1 0 Dec 19 ? 7:46 /usr/lib/netsvc/yp/ypserv -d root 123 1 0 Dec 19 ? 0:03 /usr/lib/netsvc/yp/ypbind root 133 1 0 Dec 19 ? 0:00 /usr/lib/netsvc/yp/rpc.ypupdated--More— 
  • #6: When a new command is issued in the shell, a new process starts. The first stage of a new process is when the parent process (the shell in our example) creates an exact copy of itself in the memory. The new process (the child process) has the exact environment as the parent process, but it has a different PID. This act of creating an exact copy of the parent process in the memory is called fork.In the next stage, the child process rewrites its image in the memory with the image of the command it should run. Once the image of the new process is in the memory – the new command starts to execute.This stage is called exec.After the command finishes, it terminates. Before the command terminates completely, its parent process should acknowledge its termination. The parent process receives from the child process the exit code (or an indication why the child was killed, if the child did not exit voluntarily) and is responsible for deleting the child from the process table. 
  • #7: There are 46 signals in the Unix operating systems. Each signal is associated with a number and a name. Information on the different signals can be found by using the following command:$ man –s 5 signal The kill command sends a signal to a process. By doing this the kill command enables terminating unwanted command processes. It is useful when there is a need to stop a command that takes a long time to run, or when there is a need to terminate a process that you can not quit in the normal way.In order to send a signal to a process, it’s PID has to be known. Use the ps command to get the PID. After finding the process PID, type kill followed by the PID.If you use the kill command without specifying a signal, signal 15 (SIGTERM) is sent to the process with the specified PID number. This usually causes the process to terminate.Example:$ ps -u userd1 PID TTY TIME CMD 25190 pts/0 0:02 ls 25083 pts/0 0:00 ksh$ kill 25190$ jobs[1] + Terminated ls -R / > /dev/null 2>&1 &$ Use the –u option of the ps command to find the processes that the user userd1 is running. Then the ls command is terminated with the kill command. If you need to forcibly terminate a process, you can append the –9 option to the kill command. This option is necessary for killing shells which do not respond to any other signal to terminate.Command format:$ kill –9 pid WARNING – For processes other then shell, use kill –9 command as a last resort because it is an abrupt method and does not allow for proper process termination. To abort a background job, use the specific job number as an argument to the kill command:$ jobs[1] + Running ls -R / > /dev/null 2>&1 &$$$ kill %1[1] + Terminated ls -R / > /dev/null 2>&1 &$ The pkill command works exactly like the pgrep command, except that it terminates the matching process or processes with a kill signal:$ ls -R / > /dev/null 2>&1 &[1] 25387$ $ pkill ls$ jobs[1] + Terminated ls -R / > /dev/null 2>&1 &$