1 / 27

ch03: Processes in UNIX

ch03: Processes in UNIX. Ju, Hong Taek Computer Network Lab. Keimyung University juht@kmu.ac.kr Rm: 1228, Tel: 580-5234. Objectives. Learn how to create processes Experiment with fork and exec Explore the implications of process inheritance Use wait for process cleanup

ranit
Download Presentation

ch03: Processes in UNIX

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. ch03: Processes in UNIX Ju, Hong Taek Computer Network Lab. Keimyung University juht@kmu.ac.kr Rm: 1228, Tel: 580-5234

  2. Objectives • Learn how to create processes • Experiment with fork and exec • Explore the implications of process inheritance • Use wait for process cleanup • Understand the UNIX process model

  3. 3.1 Process Identification • Unix identifies process by a unique value called the process ID • Each process also has a parent process ID • The getpid and getppid funtions return the process ID and the parent process ID, respectively • A UNIX process has several user and group IDs that convey privileges to the process • real user and group ID: process ownership • effective user and group ID: determining access permission for resources • The getegid, geteuid, getgid, getuid functions are used for retrieve relative value

  4. 3.2 Process State • The state of a process indicates its status at a particular time

  5. normal or abnormal termination running done selected to run I/O requested process created quantum expired new ready blocked I/O completed

  6. The ps utility display information about processes

  7. 3.3 UNIX Process Creation and fork • A process can create a new process by calling fork • The calling process becomes the parent, and the created process is called the child #include <sys/types.h> #include <unistd.h> pid_t fork(void); return -1 if errorreturn 0 to childreturn child's pid to parent

  8. 1 2 3 4 5

  9. 4 1 2 3

  10. 3.4 The wait Function • The parent can execute wait or waitpid to block until the child finishes • waitIf a child terminated, return its pidOtherwise return -1 and set errno • waitpidAllows you to wait for a particular process, or all process if pid is -1. Important option is NOHANG which will return 0 if there is a specified child to wait for but it has not yet terminated. #include <sys/wait.h> pid_t wait(int *stat_loc); pid_t waitpid(pid_t pid, int *stat_loc, int options);

  11. Describe the possible forms of the output?

  12. 3.5 The exec Function • The exec family of functions provides a facility for overlaying the process image of the calling process with a new image #include <unistd.h> extern char **environ; int execl(const char *path, const char *arg0, ... /*, char *(0) */); int execle (const char *path, const char *arg0, ... /*, char *(0),*/ char *const envp[]); int execlp (const char *file, const char *arg0, ... /*, char *(0) */); int execv(const char *path, char *const argv[]); int execve (const char *path, char *const argv[], char *const envp[]); int execvp (const char *file, char *const argv[]);

  13. 3.6 Background Processes and Daemons • A daemon is a background process that normally runs indefinitely • When a shell create a background process, it does not wait for the process to complete before issuing a prompt and accepting additional commands

  14. 3.7 Critical Section • The portion of code in which each process access, but should be used by only one process at a time, is called a critical section • Programs with critical section must be sure not to violate the mutual exclusion • One method of providing mutual exclusion uses a locking mechanism • Operating systems manages many shared devices that requires exclusive access by the processes in the system • A common approach is to have only one daemon handle the device with message queue

  15. Question and Answer

More Related