3 Process Control
Published:
ps axf # display process tree
ps axfj # with more info
ps axfjww # even if lines wrap around terminal
Processes
- Orphan: parents terminate before children
init
adopts it and periodically callswaitpid()
- Zombie: child terminated, but parent never calls
waitpid()
- It will show in the process tree as
<defunct>
- It will show in the process tree as
Memory mappings
When a process fork()
s, its mappings are duplicated for the child
Copy-On-Write:
- Even pieces in stack/text/code are shared and marked as read only
- Once when memory is written, OS splits it to two
- Delays duplication of memory space.
- Efficient since
fork()
is typically followed byexec()
, which will trash the memory anyway exec()
loads a new program code into memory by mapping its executable file to the text region of the address space
Process groups job control
proc1 | proc2
proc1
and proc2
share the same group ID (PGID
)
proc1 | proc2 & # & sends pipeline to background
# [1] 7106 # [<job number>] <leading PID>
proc3 | proc4 | proc5
All share the same session ID (SID
)
If you send a signal, it’s delivered to the foreground process group
jobs
: List all jobsCtrl-Z
: Suspend (SIGSTOP
) foreground job and send to the backgroundbg <job>
: Resume<job>
in the backgroundfg <job>
: Bring backgrouded<job>
into the foreground