Presentation is loading. Please wait.

Presentation is loading. Please wait.

Process Process: the UNIX abstraction of a stand-along computer that manages resources (memory, CPU, I/O resources) comprising a running program. Processes.

Similar presentations


Presentation on theme: "Process Process: the UNIX abstraction of a stand-along computer that manages resources (memory, CPU, I/O resources) comprising a running program. Processes."— Presentation transcript:

1 Process Process: the UNIX abstraction of a stand-along computer that manages resources (memory, CPU, I/O resources) comprising a running program. Processes do not share memory (default), but communicate messages using IPC. Many processes may be executing at the same time (concurrently) by time slice or quantum (20 millisecond)

2 Process Components of a Process administrator can
monitor the status of processes control how much of the CPU’s time a process gets send signals to a process suspend or halt a process’s execution Threads in a processes. Components of a Process address space: a set of data structures inside the kernel

3 Process Components of a Process (cont.)
address space: a set of memory pages that the kernel has marked for the use of the process segments for the program code that process is executing variables stack various extra info needed by the kernel while executing process owner

4 Process Components of a Process (cont.)
a set of data structures inside the kernel the process’s address space map current status of the process execution priority info about the resources used signal mask process owner

5 Process PID (Process ID) PPID (Parent’s PID)
kernel assign a unique process identification number to each newly created process PPID (Parent’s PID) UNIX does not supply a system call that create a new process running a particular program. Instead, an existing process clone (fork) itself to create a new process

6 Process the original process is called parent, the clone is called child. int kidpid; if((kidpid = fork()) == 0){ /* this is the child process */ } else { /* this is the parent */ } UID and EUID user ID who creates the process only creator and administrator can make change

7 Process GID and EGID Priority and Nice value group # in /etc/group and
GID field of /etc/passwd some systems allow a user belong to more than one group Priority and Nice value a process’s priority determines how much CPU time it will receive (internal priority) impossible to set the internal priority directly possible to change the process’s nice value

8 Process Control Terminal
other factors affecting process’s priority: amount of CPU time consumed, waiting time Control Terminal Most processes have a control terminal associated with them Control terminal determines default linkage for the standard input, output, and error. Shell’s terminal becomes the process’s terminal

9 The Life cycle of a Process
fork() system call to create a new process new process is identical to the creator except: new process has a distinct unique PID PPID is the creator’s PID new process’s accounting info is reset new process has its own copy of file descriptors a new process usually use one of exec family system calls to begin execution of a new program execl(“/bin/ls”,, “ls”, “/usr/bin”, (char *)0);

10 The Life cycle of a Process
init process has PID 1. init is responsible for forking a shell to execute the rc startup scripts all processes except the ones kernel creates are descendants of init init is also responsible for login process

11 The Life cycle of a Process
init is also responsible for process management when a process completes, it calls _exit to notify kernel that it is ready to die. it supplies a exit code (0 means sucsessful) to _exit to tell why the process is exiting. Then release address space and go to zombie state The exit code is kept for the process’s parent, so the parent knows the process (its child) exits the kernel store the exit code until parent call wait system call if the parent exits after its child

12 The Life cycle of a Process
However, if parent exits before its child, the responsibility of calling wait is given to init. Init may not does this job correctly, resulting in a zombie state to be left on the system usually cannot be killed does not cause any real problem

13 Process State Transition Diagram
1 User Running Interrupt, interrupt return Sys call interrupt Return to user return 9 2 7 exit preempt Preempted Zombie Kernel Running reschedule sleep Ready to Run in Memory Asleep in Memory 4 3 wakeup Created Enough mem 8 Swapout Swapout fork Swapin 6 5 wakeup Sleep, Swapped Not enough mem Ready to Run, Swapped

14 Command kill kill - Sends a signal to a running process SYNOPSIS
kill [-signal_name | -signal_number] process_ID default is SIGTERM (15), which terminates processes that do not ignore or catch the signal. special PIDs: 0: signal is sent to all processes having a process group ID equal to sender’s process group ID, except PIDs 0 and 1.

15 Command kill -1: If sender’s EUID  0 (root), signal is sent to all processes with a GID = sender’s GUID, except PIDs 0 and 1. -1: If sender’s EUID = 0 (root), signal is sent to all processes, excluding 0 and 1. Kill -l: : Lists signal names HUP INT QUIT ILL TRAP ABRT EMT FPE KILL BUS SEGV SYS PIPE ALRM TERM URG STOP TSTP CONT CHLD TTIN TTOU IO XCPU

16 Command kill kill 0: This command sends the SIGTERM signal to all members of the shell process group. This includes all background processes started with &. Although the signal is sent to the shell, it has no effect because the shell ignores the default signal 15. kill -KILL 0: terminates all of your processes and logs yourself out sends SIGKILL to all members of shell process group. Because shell cannot ignore SIGKILL, this also terminates the login shell and logs you out. If you are using multiple windows, this closes the active window.

17 Signal event kill -KILL -1: terminate all the processes that you own:
sends SIGKILL to all the processes that you own, even those that belong to other process groups. If you are using multiple windows, closes all the windows. kill -KILL sends SIGKILL to processes and The SIGKILL signal usually cannot be ignored or caught. kill -USR1 1103 sends SIGUSR1 signal to process 1103. The action taken on SIGUSR1 signal is defined by the particular application you are running.

18 Signal event When a process receives a signal, 2 things happen
if process has designated a handler routine for the signal, the routine is called with info about the context in which the signal was delivered. Otherwise, kernel takes some default actions: actions vary from signal to signal terminate the process or core dump

19 Signal catch a signal: specify a handler routine
when the handler completes, execution restarts at the point where the signal was received ignore or block a signal: set mask command (ssetmask) ignored signal has no effect on process blocked signals are queued until an explicit unblocking event is activated. Table 5.1

20 Unix signals Name description default catch block dump
1 HUP hangup terminate Y Y N core 2 INT interrupt terminate Y Y N 3 QUIT quit terminate Y Y Y 9 KILL kill terminate N N N a BUS bus error terminate Y Y Y a SEGV segment fault terminate Y Y Y 15TERM software termination terminate Y Y N a STOP stop stop N N N a TSTP keyboard stop stop Y Y N a CONT continue after stop ignore Y N N a USR1/USR2 user-defined terminate Y Y N

21 Signal usage of signals Examples: communication between processes
interrupt|terminate process by control terminal Examples: <control-C> on the keyboard: terminal driver receives the character, sends INT or TERM to the active processterminate or abort program send a STOP or TSTP signal to stop a process (put it into sleep) and a CONT signal to restart the stopped process

22 Signal process can be stopped in the following ways: user request <control-Z> is typed to an interactive process background process try to access its control terminal Nice value: a hint to kernel to determine how much CPU time a process can get compared to other processes Lower nice value --> high priority BSD: -19 ~+19 ATT: 0 ~ 39


Download ppt "Process Process: the UNIX abstraction of a stand-along computer that manages resources (memory, CPU, I/O resources) comprising a running program. Processes."

Similar presentations


Ads by Google