3. CoreLinuxforRedHatandFedoralearningunderGNUFreeDocumentationLicense-Copyleft(c)AcácioOliveira2012
Everyoneispermittedtocopyanddistributeverbatimcopiesofthislicensedocument,changingisallowed
Create, monitor and kill processes
Process wraps up everything needed to know about a running piece of software.
Meta information includes the machine code for the software, and things like what
user/group pair is running the process, when it was started, what command line was, etc.
Pertinent parts of a process:
PID; PPID; UID/GID; Command; Start Time; CPU Time; CWD; State; TTY; Environment; Priority; Nice; Level
Processes structure
3
PID
Process ID
•Linux uses this number to uniquely identify every process on the computer
•Number from 1-32768 ( default - can change the maximum )
•Assigns new PIDs incrementally by 1, 2 or 4
•Loops back to 1 after hitting the maximum
PPID
Parent Process ID
•PID of the process that started this one
7. CoreLinuxforRedHatandFedoralearningunderGNUFreeDocumentationLicense-Copyleft(c)AcácioOliveira2012
Everyoneispermittedtocopyanddistributeverbatimcopiesofthislicensedocument,changingisallowed
Create, monitor and kill processes
Job control - Ability to selectively suspend execution of processes and continue their execution later.
A job is a process or a pipeline of processes that were started by the shell.
Job control
7
job which receives keyboard input is called the foreground job.
•When a foreground process is running, it receives keyboard input and signals.
•Processes started are run in foreground by default and continue until they exit.
To run a process in background – input command followed by special character &
•Processes running in the background may still send output to the terminal.
•They do not receive keyboard input unless they are brought to the foreground.
When bash starts a background job, it prints a line with:
- job number and - process ID of last process in pipeline
9. CoreLinuxforRedHatandFedoralearningunderGNUFreeDocumentationLicense-Copyleft(c)AcácioOliveira2012
Everyoneispermittedtocopyanddistributeverbatimcopiesofthislicensedocument,changingisallowed
Create, monitor and kill processes
Control jobs
9
key sequences entered to foreground processes:
Key Signal Meaning Usage
Ctrl+C SIGINT Interrupt Interrupt the program running in the foreground
Ctrl+Z SIGSTOP Suspend Suspend the program running in the foreground
cmds entered to control background processes.
Command Meaning Usage
fg foreground Run the background job in the foreground. If it has suspended, restart it.
bg background Restart a suspended job.
fg makes most recently executed job a foreground job.
You can specify a specific job number. (Ex. fg 2 will make job 2 run in the foreground)
bg makes most recently executed job continue to run in background.
You can make a specific job run in the background by specifying a job number (Ex. bg 2)
11. CoreLinuxforRedHatandFedoralearningunderGNUFreeDocumentationLicense-Copyleft(c)AcácioOliveira2012
Everyoneispermittedtocopyanddistributeverbatimcopiesofthislicensedocument,changingisallowed
Create, monitor and kill processes
Monitoring processes
11
ps – process status
options supported by ps are somewhat complex.
GNU version supports: Unix98 options (letters); BSD options (dash); GNU options (two dashes).
To ... Unix98 BSD
- Show all processes ps -ax ps -A ps -e
- Show full info ps -u (user format) ps -f (full listing)
- Show full info for all processes ps -aux ps -ef ps -Af
foo:~ $ ps -f
UID PID PPID C STIME TTY TIME CMD
georgem 987 612 0 20:32 pts/2 00:00:00 /bin/bash
georgem 3398 987 0 21:11 pts/2 00:00:00 ps -f
foo:~ $ ps u
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
georgem 987 0.0 1.7 4676 2040 pts/2 S 20:32 0:00 /bin/bash
georgem 3399 0.0 0.5 2524 696 pts/2 R 21:11 0:00 ps u
Ex:
ps -w – display in wide format
ps -f – display in forest of processes, similar to output of pstree - Generate hierarchical view of
processes.
12. CoreLinuxforRedHatandFedoralearningunderGNUFreeDocumentationLicense-Copyleft(c)AcácioOliveira2012
Everyoneispermittedtocopyanddistributeverbatimcopiesofthislicensedocument,changingisallowed
Create, monitor and kill processes
Processes states
12
5 basic process states:
1. Runnable Process is running, or is set to run.
•Linux is a multi-tasking it’s hard to see exactly when processes are running (switched so quickly),
•state is runnable, indicating that the scheduler will provide CPU time when it’s available.
2. Stopped Process will not get CPU time
•Nothing happens to the process - it’s still in memory, poised, ready to go.
•But when it’s put in the stopped state, scheduler will not put it on the CPU.
•Files/network connections remain open, but network connections may drop after a time (timeout).
3. Blocked/Sleeping – interrutible Process is waiting for some event
•Event can be an alarm from a sleep system call, or a signal or other external event.
•Interruptible means that other processes/events can break the sleep.
4. Blocked/Sleeping - non-interrutible Sleep state generally caused by IO operations
accessing a drive, communicating with network, etc.
•Non-interruptible means that other processes/events can not break this sleep.
•This process is unable to respond to signals.
5. Zombie/Defunct Exited process whose parent did not wait() on child
•Does not consume resources beyond a PID and meta information storage ( < 1k generally )
•Generally caused by2 situations:
- Bug in software
- Overly taxed machine