Presentation is loading. Please wait.

Presentation is loading. Please wait.

Concurrent Processes Processes can concurrently run same program. Processes can concurrently run same program. Processes can start other processes. Processes.

Similar presentations


Presentation on theme: "Concurrent Processes Processes can concurrently run same program. Processes can concurrently run same program. Processes can start other processes. Processes."— Presentation transcript:

1 Concurrent Processes Processes can concurrently run same program. Processes can concurrently run same program. Processes can start other processes. Processes can start other processes. UNIX provides concurrency functions UNIX provides concurrency functions

2 Creating New Processes system -- makes a shell system -- makes a shell Exec -- replace this process with a new one Exec -- replace this process with a new one Fork -- start a concurrent process Fork -- start a concurrent process

3 Example “ System ” int main() { char buffer[80]; strcpy(buffer, “ wc *.* ” ); system(buffer); }

4 The exec( ) Family char *path, *file; char *arg0, *arg1,..., *argn; char *argv[ ]; int ret; ret = execl (path, arg0, arg1,..., argn, (char *)0); ret = execv (path, argv); ret = execlp (file, arg0, arg1,..., argn, (char *) 0); ret = execvp (file, argv);

5 The fork( ) Facility Basic process creation primitive. Basic process creation primitive. Duplicates the calling process. Duplicates the calling process. New process child process New process child process Initiating process is parent. Initiating process is parent. Returns child ’ s process-id Returns child ’ s process-id

6 Inherited Data and File Descriptors Forked child has instances of current values of the variables and open file descriptors. Forked child has instances of current values of the variables and open file descriptors. Variables; “ pass ” by copy Variables; “ pass ” by copy Read/write pointers for a file; reference Read/write pointers for a file; reference

7 wait( ) int wait (int * status) int wait (int * status) Suspends execution of process while child runs Suspends execution of process while child runs Parent resumes upon child termination Parent resumes upon child termination When the first child process terminates When the first child process terminates Normally returns process-id of exiting child. Normally returns process-id of exiting child. On error, wait( ) returns a -1, usually meaning no child exists on which to wait. On error, wait( ) returns a -1, usually meaning no child exists on which to wait.

8 Zombies and Premature Exits Zombie processes are ones that somehow lose connection with the parent. How? Zombie processes are ones that somehow lose connection with the parent. How? Zombie occupies a slot in process table, but uses no system resources. Zombie occupies a slot in process table, but uses no system resources. Zombie cleared when parent “ claims ” child Zombie cleared when parent “ claims ” child Wait removes chance of zombie??? Wait removes chance of zombie??? Parent exits B4 children  premature exit Parent exits B4 children  premature exit

9 Process and Group Id ’ s pid = getpid( ); its own process id pid = getpid( ); its own process id pid = getppid( ); parent process id pid = getppid( ); parent process id newpg = setpgrp( ); change group newpg = setpgrp( ); change group pgid = getpgrp( ); access group pgid = getpgrp( ); access group

10 UNIX Signals SIGHUP- The hangup signal, sent upon user logout SIGINT- Interrupt signal, sent on user break signal SIGQUIT- Quit signal, sent when user hits quit key SIGILL - Illegal Instruction signal SIGTRAP- Trace trap signal used by debuggers SIGFPE- Floating-Point exception signal SIGKILL- Sent process n to terminate process m SIGSYS- Bad argument to a system call signal SIGPIPE- Write on a pipe with no one to read it SIGALRM- Alarm clock signal used for software timers SIGTERM- Software signal to terminate process SIGUSR1- user signal SIGUSR2- user signal

11 pause( ) int pause( ) pause( ) suspends the calling process, without wasting resources, until some kind of signal is received.


Download ppt "Concurrent Processes Processes can concurrently run same program. Processes can concurrently run same program. Processes can start other processes. Processes."

Similar presentations


Ads by Google