Section 1

Preview this deck

exit()

Front

Star 0%
Star 0%
Star 0%
Star 0%
Star 0%

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Active users

0

All-time users

0

Favorites

0

Last updated

6 years ago

Date created

Mar 1, 2020

Cards (12)

Section 1

(12 cards)

exit()

Front

after the program finishes execution, it calls exit() this system call: -takes the result (return value) of the process as an argument -closes all open files, connections, etc. -deallocates memory -deallocates most of the OS structures supporting the process -Checks if parent is alive: --if so, it holds the result value until parent requests it; in this case, process does not really die, but it enters the zombie/defunct state --if not, it deallocates all data structures, the process is dead -cleans up all waiting zombies Process termination is the ultimate garbage collection (resources reclamation)

Back

Orphaned processes

Front

Parent terminates before the child: -in some instances, the child becomes an orphan process --in UNIX, parent automatically becomes the init process -in other instances, all children are killed (depending on the shell) --bash kills all child process when it receives a SIGHUP -Child can orphan itself to keep running in the background --nohup command (also prevents it from being killed when SIGHUP is sent)

Back

Memorize Process Lifecycle

Front

Back

exec()

Front

overlays a process with a new program --pid does not change --arguments to new program may be specified --code, stack, and heap are overwritten ---sometimes memory mapped files are preserved -new program will begin at main() -does not create a new process()!!!!!!!!!!!

Back

Unix Shell

Front

when you log into the unix shell the OS creates a shell process for you to use. Every command you type into the shell is a child of your shell process if you type an & after your command, Unix will run the process in parallel with your shell, otherwise your next shell command must wait until the first one completes

Back

zombie process

Front

process has terminated but parent process has not collected its status

Back

Process Control

Front

OS must include calls to enable special control of a process: Priority manipulation: -nice(), which specifies base process priority (initial priority) -in UNIX, process priority decays as the process consumes CPU Debugging support: -ptrace() allows a process to be put under control of another process -the other process can set breakpoints, examine registers, etc. Alarms and time -sleep puts a process on a timer queue waiting for some number of seconds, supporting an alarm functionality

Back

kill()

Front

A parent can terminate a child using kill() -kill() is also used for interprocess communication -sends a signal to a specified process (identified by its PID) -the receiving process can define signal handlers to handle signals in a particular way -if a handler for that signal does not exist, the default action is taken

Back

wait() system call

Front

causes the parent process to wait for the child process to terminate -allows the parent process to get return value from the child -puts parent to sleep waiting for a child's result -when a child calls exit(), the OS unblocks the parent and returns the value passed by exit() as a result of the wait call (along with the pid of the child) -if there are no children alive, wait() return immediately -also if there are zombies waiting for their parents, wait() returns one of the values immediately (and deallocates the zombie)

Back

Process State

Front

consists of at least: -the code for running the program -the program counter (PC) indicating the next instruction -an execution stack with the program's call chain (the stack) and the stack pointer (SP) -the static data for running the program -space for dynamic data (the heap), the heap pointer (HP) -values of CPU registers -a set of OS resources in use (e.g. open files) -process indentifier (PID) -process execution state (ready, running, etc.)

Back

fork()

Front

used to create an identical process to the parent. -copies variables values and program counter from parent to child -return twice: once to the parent and once to the child -return value is different in the parent and child (this is the only difference!!!) --in parent, return values is child process id --in child it is 0 -both processes begin execution from the same point -each process has its own memory and its own copy of each variable --changes to variables in one process are not reflected in the other

Back

How to create a process

Front

One process can create other processes -the created processes are the child processes -the creator is the parent process In some systems the parent defines (or donates) resources and privileges to its children The parent can either wait for the child to complete or continue in parallel

Back