1 / 22

Process

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 .

frayne
Download Presentation

Process

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

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 • 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 ofdata 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) • 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 • 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 • 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. 1 6 8 3 5 9 2 7 4 Process State Transition Diagram User Running Interrupt, interrupt return Sys call interrupt Return to user return exit Preempted preempt Kernel Running Zombie reschedule Ready to Run in Memory sleep Asleep in Memory wakeup Created Enough mem Swapout Swapout fork Swapin 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 17285 15692 • sends SIGKILL to processes 17285 and 15692. 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 • 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

More Related