This document discusses Unix process states, zombie processes, running jobs in the background, and killing processes with signals. It covers the following key points:
1. Process states include running, waiting, zombie, and runnable. A zombie process is one whose parent hasn't issued a wait call, while an orphan has no living parent process.
2. Background jobs run without user intervention using the & operator or nohup command. The jobs command lists background jobs.
3. The kill command terminates processes by sending signals. It can target processes by PID or send a specific signal number.
Introduction to Unix OS processes, jobs, signals and killing processes
1. Introduction to Unix and OS
Module 2 Continued……
Dr. Girisha G S
Dept. of CSE
SoE,DSU, Bengaluru
1
2. Agenda
• Process States and Zombies
• Running jobs in background
• Killing processes with Signals
2
3. Process States
1 Runnable Sate :
2. Running State :
3. Waiting (or sleeping)/Suspended State:
4. Zombie state :
Process states are :
Figure. Process State Diagram
3
4. Zombie Process
A zombie process is one which has exited, but its parent hasn't yet issued a wait()
system call to observe its termination state
Orphan Process
Process whose parent process no more exists i.e. either finished or terminated without
waiting for its child process to terminate is called an orphan process.
4
5. Running Jobs in Background
Foreground Job: The process that is connected to the terminal is called
the foreground job
E.g. A foreground process begins by typing a command at the prompt. For
example, type ls to see a simple listing of the files in the current directory
Background Job: Process that runs behind the scenes (i.e., in the background) and
without user intervention
E.g. sorting a large file in the background
Jobs
- This command lists jobs running in the background
E.g $ jobs
[3]+ running grep ‘director emp.dat &
[2]- running sort employee.data>sortedlist.data &
[1] supended wc –l hugefile.txt
5
6. 2. nohup- no hangup
- nohup command permits execution of the process even after the user has
logged out.
- Use & with it as well
E.g. $nohup sort emp.lst &
586
sending output to nohup.out
Two ways of starting jobs in background
1. With shell’s & operator
The shell’s & operator used to run a job in the background
E.g. Sort a file called ‘foo’ and place the results in a file called ‘bar’
$ sort <foo >bar &
550 //jobs PID
- This method run in the background but the process will be killed if you logout.
6
7. Killing processes with Signals
- Some times you want or need to terminate a process.
- The following are some reasons for stopping a process
• Its using too much CPU time
• It is running too long without producing the expected
output
• Its no longer useful
How to get out of these situations?
• Use kill command to stop the background process
• press <ctrl-c> to stop a command that is not in the background
7
8. Kill – premature termination of a process
- Kill command is used to terminate a process
- Issuing a kill command sends a signal to a process
- Unix programs can send or receive more than 20 signals each of
which is represented by a number
- Use kill -l to list all signal names and numbers
8
9. Two forms of using kill command
Kill PIDs
– uses one or more PIDs as arguments
Kill -Number PIDs
- Uses signal number as option and PID as arguments
Examples
1. kill a process whose PID is 123
$ kill 123
2. Kill a process with signal number 9 whose PID is 123
$ kill -9 123
9
Editor's Notes
we will walk you through different process states in Linux. This will be helpful analyzing processes during troubleshooting. Process states defines what process is doign and what it is expected to do in near time. From the birth (spawn) till death (kill/terminate or exit), process has a life cycle going through several states.
running or runnable, it is just waiting for the CPU to process it, process which is being served by CPU currently.
S: Interruptible sleep, waiting for an event to complete, such as input from the terminal
Zombie, we discussed in a previous lesson that zombies are terminated processes
A zombie process is a process whose execution is completed but it still has an entry in the process table
due to lack of correspondence between the parent and child processes. Usually, a parent process keeps a check on the status of its child processes through the wait() function. When the child process has finished, the wait function signals the parent to completely exit the process from the memory. However, if the parent fails to call the wait function for any of its children, the child process remains alive in the system as a dead or zombie process.
The process that is connected to the terminal is called the foreground job. A job is said to be in the foreground because it can communicate with the user via the screen, and the keyboard.
Jobs that are disconnected from the terminal for input and output are called "background" jobs sorting a large file) can be placed in the background
As known a process terminates normally when it finishes its works and exits. While it can also termainate abnormally because of an error or intervention by the user. The owner of the command can use command or a key <ctrl-c> to terminate the process
To cancel a process use the kill command
The primary purpose of the kill command is used to send a signal to the process