Today’s topic UNIX process relationship and job control

Slides:



Advertisements
Similar presentations
Recitation 8 (Nov. 1) Outline Process & job control Lab 5 Reminder Lab 5: Due Thursday Minglong Shao Office hours: Thursdays 5-6PM.
Advertisements

Lab 9 CIS 370 Umass Dartmouth.  A pipe is typically used as a one-way communications channel which couples one related process to another.  UNIX deals.
June 1, 1999Foreground/Background Processing1 Introduction to UNIX H. Foreground/Background Processing.
1 CS345 Operating Systems Φροντιστήριο Άσκησης 1.
Pseudo Terminals Concept Application APIs. Overview A pseudo terminal (PTY) is a user level program that appears to be a terminal device to another program.
Using tcpdump. tcpdump is a powerful tool that allows us to sniff network packets and make some statistical analysis out of those dumps. tcpdump operates.
15-213, Fall 06 Outline Shell Lab Processes Signals.
Process groups, sessions, controlling terminal, and job control Process relationship: –Parent/child –Same group –Same session.
Process Relationships Terminal and Network Logins Process Groups and Sessions Job Control Relationships.
Lesson 10-Controlling User Processes. Overview Managing and processing processes. Managing jobs. Exiting/quitting when jobs have been stopped.
Process Relationships Chien-Chung Shen CIS, UD
UNIX Process Control Bach 7 Operating Systems Course Hebrew University Spring 2007.
1 Processes and Pipes COS 217 Professor Jennifer Rexford.
Linux+ Guide to Linux Certification, Second Edition
The Process - Part II. Process Attributes  Each UNIX process is associated with a number of attributes which help the system control the running and.
Fork and Exec Unix Model Tutorial 3. Process Management Model The Unix process management model is split into two distinct operations : 1. The creation.
Carnegie Mellon 1 Processes, Signals, I/O, Shell Lab : Introduction to Computer Systems Recitation 9: 10/21/2013 Tommy Klein Section B.
The Programming Interface. Main Points Creating and managing processes – fork, exec, wait Performing I/O – open, read, write, close Communicating between.
UNIX Processes. The UNIX Process A process is an instance of a program in execution. Created by another parent process as its child. One process can be.
Linux in More Detail Shirley Moore CPS5401 August 29,
The Shell Chapter 7. Overview The Command Line Standard IO Redirection Pipes Running a Program in the Background Killing (a process!)
Linux+ Guide to Linux Certification, Second Edition Chapter 10 Managing Linux Processes.
The kernel considers each program running on your system to be a process A process lives as it executes, with a lifetime that may be short or long A process.
Operating Systems Processes 1.
Process Models, Creation and Termination Reference –text: Tanenbaum ch. 2.1.
What is a Process? u A process is an executable “cradle” in which a program may run u This “cradle” provides an environment in which the program can run,
1 Lecture 6 Introduction to Process Management COP 3353 Introduction to UNIX.
Lesson 3-Touring Utilities and System Features. Overview Employing fundamental utilities. Linux terminal sessions. Managing input and output. Using special.
Course materials may not be reproduced in whole or in part without the prior written permission of IBM. 5.1 © Copyright IBM Corporation 2008 Unit 9 Working.
ACCESS CONTROL. Components of a Process  Address space  Set of data structures within the kernel - process’s address space map - current status - execution.
The Process CIS 370, Fall 2009 CIS UMassD. The notion of a process In UNIX a process is an instance of a program in execution A job or a task Each process.
CSC414 “Introduction to UNIX/ Linux” Lecture 3
Agenda Managing Processes (Jobs) Command Grouping Running jobs in background (bg) Bringing jobs to foreground (fg), Background job status (jobs) Suspending.
1 Lecture 19: Unix signals and Terminal management n what is a signal n signal handling u kernel u user n signal generation n signal example usage n terminal.
Dsh: A Devil Shell COMPSCI210 Recitation 14 Sep 2012 Vamsi Thummala.
Agenda The Bourne Shell – Part I Redirection ( >, >>,
CS241 Systems Programming Discussion Section Week 2 Original slides by: Stephen Kloder.
An Introduction to processes R Bigelow. A Unix Process A process in Unix is simple a program The Unix system is made up of a group of processes all interacting.
CS241 Systems Programming Discussion Section Week 2 Original slides by: Stephen Kloder.
4.1 Operating Systems Lecture 9 Fork and Exec Read Ch
Process Related System Calls By Neha Hulkoti & Kavya Bhat.
Process Relationships Chien-Chung Shen CIS/UD
CSCI 4061 Recitation 2 1.
G.Jyostna.
Week 3 Redirection, Pipes, and Background
Process relationships
Chapter 3: Process Concept
Topic 3 (Textbook - Chapter 3) Processes
Unix Process Management
Chapter 3: Processes.
Example questions… Can a shell kill itself? Can a shell within a shell kill the parent shell? What happens to background processes when you exit from.
Chapter 3: Processes.
CGS 3763 Operating Systems Concepts Spring 2013
Fork and Exec Unix Model
Lecture 2: Processes Part 1
Process Models, Creation and Termination
The Linux Command Line Chapter 10
Operating Systems Lecture 6.
Operating Systems Lecture 12.
Chapter 3: Processes.
CHAPTER 13 Processes.
CSC 140: Introduction to IT
Controlling Processes
Chapter 3: Processes.
CSE 451: Operating Systems Winter 2003 Lecture 4 Processes
Processes in Unix and Windows
CSE 451: Operating Systems Autumn 2004 Module 4 Processes
Lab 6: Process Management
Lecture 6 Introduction to Process Management
Presentation transcript:

Today’s topic UNIX process relationship and job control Groups, Sessions, Foreground and background processes Our program can now have many processes, when Ctrl-C is typed, which process should receive SIGINT?

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 shell proc1 proc3 proc2 proc4 proc5

Session A session can have a single controlling terminal 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? So that the terminal device driver knows where to send the terminal input and the terminal-generated signals. pid_t tcgetpgrp(int filedes); Return the process group ID of the foreground process group associated with fieldes. int tcsetpgrp(int filedes, pid_t pgrpid); If the process has control terminal, set the foreground process group ID to 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.

Review What do tcgetpgrp and tcsetpgrp do? How are foreground and background processes different? How can a shell make sure that the signal is only sent to the foreground processes?