DOC PREVIEW
FSU COP 5570 - Session

This preview shows page 1-2-3-4-5 out of 15 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 15 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 15 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 15 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 15 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 15 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 15 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Today’s topicProcess groupsSlide 3Slide 4SessionSlide 6Slide 7Slide 8Slide 9Slide 10Slide 11Shells without job controlShell without job controlSlide 14Slide 15Today’s topic•UNIX process relationship–Parent/child–Group–Session•Job control–Foreground and background processes–Given that many processes can be executed concurrently, which processes should have accesses to the keyboard/screen (I/O)?Process groups–A process group is a collection of (related) processes. Each group has a process group ID.–Each group has a group leader who pid = pgid–To get the group ID of a process: pid_t getpgrp(void)–A signal can be sent to the whole group of processes.•Process groups:–A process may joint an existing group, create a new group.int setpgid(pid_t, pid, pid_t, pgid)•A process can set group ID of itself or its children•_POSIX_JOB_CONTROL must be defined•Most shells with job control create new group for each line of command (job).•Sessions–A session is one or more process groups proc1 | proc2 & proc3 | proc4 | proc5– results in a session with three groups, see ‘ps –j’–A login shell is a session in general.Login shellproc2proc1proc5proc4proc3Session•A session can have a single controlling terminal for performing I/O–Terminal device for a terminal login–Pseudo-terminal device for a network login–The I/O devices somewhat link to the window and keyboard.•The session leader that establishes the connection to the control terminal is called the controlling process.Session•Only one I/O device for all processes (and process groups) in a session. Which process should get the input from the keyboard?•Foreground and background process–One foreground group–Many background groups–Input•Only foreground group•Terminals’ interrupt signals are only sent to the processes in the foreground group.–Output•Typically shared•Sessions–To establish a new session:pid setsid(void);•Process become the session leader•Process become a new group leader of a new group•Process has no controlling terminal (break up the old one)–Each shell is a session. When a shell is created, a terminal must be setup.•Fails if the caller is a group leader.–A process can open file /dev/tty to talk to the controlling terminal regardless how standard IO are redirected.•A way to by pass I/O redirection, see example1.c•How to make a group foreground and background?pid_t tcgetpgrp(int filedes);int tcsetpgrp(int filedes, pid_t pgrpid);–Pgrpid must be group ID in the same session.•Job control–Allows start multiple jobs from a single terminal and control which job can access the terminal.–Foreground jobs can access terminal–Background jobs may not:•When a backgound job try to read, SIGTTIN signal is sent•A background job must be able to output to the terminal (options may be set by the stty command)–See control.c for an example of switching terminal among groups.•Orphaned process group:–Parent of every member is either in the orphaned group or is not a member of the group’s session.–Happens when a process forks a child and then dies.•The child becomes a member of the orphaned group.•Can have problems: the child may transform from a foreground process to a background process automatically.–Remember in the control.c program, foreground group is set in both the parent and the child.–Can be in an inconsistent state.–If any IO is involved, strange things may happen.•How to make sure that a shell program handles terminal I/O and signals correctly–Create a new group for each job•Both parent and child do setpgid–For foreground job:•After fork, shell set tcsetpgrp to give foreground jobs control over terminal•Shell waits for all foreground processes in the foreground job to finish. After that, shell set tcsetpgrp to itself and print the prompt.–For background job:•Create a separate group so that processes in background jobs do not have access to terminal.Shells without job control•The original Bourne shell (sh) does not have job control.•Try sh on program.cs.fsu.edu to see the behavior•The key question: how are io and signals handled in this situation?Shell without job control•No new sessions or process groups are created –All processes are in the same session and same group •No background process groups vs. foreground process groups –It will not use tcsetpgrp() to set foreground process group •We do have background process(es) in shells without job control, such as sh –In the sense that parent process (sh) will not wait for background process(es) to finish –After forking a child process to run a command, the shell continues to show prompt to accept user input –The next line of user input should be the next command line to shell, not the input to the background process(es)Shell without job control•How do we guarantee that the next line is for shell, not read by the background command? •It depends on if the standard input of the command has been redirected to a file –If yes, the shell does nothing special –If no, the shell will redirect the standard input of the command to /dev/null before invoking the command –As a consequence, in case the command will read from standard input, it will get nothing (immediately encounter end of file)Shell without job control•How about accessing file /dev/tty in shells without job control? –Every process can open it –Since, from terminal device driver’s viewpoint, they are all in the same process group (no background process group or foreground process


View Full Document

FSU COP 5570 - Session

Download Session
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Session and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Session 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?