Presentation is loading. Please wait.

Presentation is loading. Please wait.

Process Relationships Chien-Chung Shen CIS/UD

Similar presentations


Presentation on theme: "Process Relationships Chien-Chung Shen CIS/UD"— Presentation transcript:

1 Process Relationships Chien-Chung Shen CIS/UD cshen@udel.edu

2 Introduction Every process has a parent process ( init is its own parent) The parent is notified when the child terminates; parent obtains the child’s exit status Process group Session Login shell and other (child) processes Signal

3 Terminal Login Dumb terminal connected to a host with hard-wired connections: local (directly connected) or remote (via a modem) Login came through a terminal device driver in the kernel  a fixed # of terminal devices and hence logins GUI and windowing systems  “terminal windows” emulate character-based terminals

4 Process Group Process has PID and belongs to a group A process group is a collection of processes associated with the same job, that can receive signals from the same terminal Process group ID #include pid_t getpgrp(void); pid_t getpgid(pid_t pid ); getpgid(0) == getpgrp()( calling process) Each process group has a leader, whose process group ID == its PID

5 Sessions A session is a collection of one or more process groups proc1 | proc2 & proc3 | proc4 | proc5

6 Controlling Terminal A session can have a single controlling terminal - the terminal device (a terminal login) or the pseudo terminal device (a network login) on which we log in The session leader that establishes the connection to the controlling terminal is the controlling process The process groups within a session can be divided into a single foreground process group and one or more background process groups If a session has a controlling terminal, it has a single foreground process group and all other process groups in the session are background process groups Whenever press terminal’s interrupt key (^C), the interrupt signal is sent to all processes in the foreground process group

7 Controlling Terminal A session can have a single controlling terminal The session leader that establishes connection to the controlling terminal is the controlling process For a session with a controlling terminal, there is one foreground group and multiple background groups SIGINT ( ^C ) is sent to all processes in the foreground process group

8 Job Control (1) Start multiple jobs (groups of processes) from a single terminal and control which jobs can access the terminal and which jobs are run in the background A job is simply a collection of processes, often a pipeline of processes vi main.c // starts a job of one process in the foreground pr *.c | lpr & make all & // start two jobs in the background

9 Job Control (2) When the jobs are done and we press RETURN, the shell tells us that the are complete The reason we have to press RETURN is to have the shell print its prompt The shell doesn’t print the changed status of background jobs at any random time—only right before it prints its prompt, to let us enter a new command line If the shell didn’t do this, it could produce output while we were entering an input line

10 Job Control (3) Terminal driver looks for three special characters, which generate signals to the foreground process group – interrupt character (Control-C) generates SIGINT – quit character (Control-backslash) generates SIGQUIT – suspend character (Control-Z) generates SIGTSTP Only the foreground job receives terminal input Not an error for a background job to try to read from the terminal, but the terminal driver detects this and sends a special signal to the background job: SIGTTIN, which normally stops the background job $ cat > out & $ fg %1...... ^D Shell starts the “ cat ” process in the background, but when cat tries to read its standard input (the controlling terminal), the terminal driver, knowing that it is a background job, sends SIGTTIN signal to the background job. The shell detects this change in status of its child and tells us that the job has been stopped. We then move the stopped job into the foreground with the shell’s fg command (and send SIGCONT

11 Job Control

12 How Shell Executes Programs Relation to process groups, controlling terminals, and sessions Use sh (Bourne shell with no job control on Solaris) ps –o pid,ppid,pgid,sid,comm | cat1 | cat2


Download ppt "Process Relationships Chien-Chung Shen CIS/UD"

Similar presentations


Ads by Google