1 / 11

Concurrent Processes

Concurrent Processes. Processes can concurrently run same program. Processes can start other processes. UNIX provides concurrency functions. Creating New Processes. system -- makes a shell Exec -- replace this process with a new one Fork -- start a concurrent process. Example “ System ”.

geneyu
Télécharger la présentation

Concurrent Processes

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. Concurrent Processes • Processes can concurrently run same program. • Processes can start other processes. • UNIX provides concurrency functions

  2. Creating New Processes • system -- makes a shell • Exec -- replace this process with a new one • 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. • Duplicates the calling process. • New process child process • Initiating process is parent. • 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. • Variables; “pass” by copy • Read/write pointers for a file; reference

  7. wait( ) • int wait (int * status) • Suspends execution of process while child runs • Parent resumes upon child termination • When the first child process terminates • Normally returns process-id of exiting child. • 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 occupies a slot in process table, but uses no system resources. • Zombie cleared when parent “claims” child • Wait removes chance of zombie??? • Parent exits B4 children  premature exit

  9. Process and Group Id’s • pid = getpid( ); its own process id • pid = getppid( ); parent process id • newpg = setpgrp( ); change 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.

More Related