Scis.regis.edu ● CS 468: Advanced UNIX Class 5 Dr. Jesús Borrego Regis University 1.

Slides:



Advertisements
Similar presentations
1 CS345 Operating Systems Φροντιστήριο Άσκησης 1.
Advertisements

Week Fourteen Agenda Announcements Final Exam True/False -100 questions (1 point per question) Multiple Choice - 40 questions (2 points per question)
1 Select and poll and Signals CS 241 April 6, 2012 University of Illinois.
UNIX Process Control Bach 7 Operating Systems Course Hebrew University Spring 2007.
CS 311 – Lecture 14 Outline Process management system calls Introduction System calls  fork()  getpid()  getppid()  wait()  exit() Orphan process.
Unix Processes.
Page 1 Task Control: Signals and Alarms Chapter 7 and 8 B. Ramamurthy.
Process Process: the UNIX abstraction of a stand-along computer that manages resources (memory, CPU, I/O resources) comprising a running program. Processes.
Signals Hua LiSystems ProgrammingCS2690Signals. Topics: Sending Signals -- kill(), raise() Signal Handling -- signal() sig_talk.c -- complete example.
CS Lecture 16 Outline Inter-process Communication (IPC) – Pipes – Signals Lecture 161CS Operating Systems 1.
B. RAMAMURTHY Pag e 1 Task Control: Signals and Alarms Chapter 7 and 8 7/2/2015.
CSc 352 Signal Handling in Unix Saumya Debray Dept. of Computer Science The University of Arizona, Tucson
Process Description and Control A process is sometimes called a task, it is a program in execution.
University of Pennsylvania 9/12/00CSE 3801 Multiprogramming CSE 380 Lecture Note 3.
Process states inWindows 2000 and Linux Module 2.1.
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.
Process Description and Control Chapter 3. Major Requirements of an OS Interleave the execution of several processes to maximize processor utilization.
Operating Systems Yasir Kiani. 22-Sep Agenda for Today Review of previous lecture Process management commands: bg, fg, ^Z, jobs, ^C, kill Thread.
Today’s Topics Introducing process: the basic mechanism for concurrent programming –Process management related system calls Process creation Process termination.
Process. Processes A process is an abstraction for sequence of operations that implement a computation/program. A process may be manipulated, suspended,
Lecture 3 Process Concepts. What is a Process? A process is the dynamic execution context of an executing program. Several processes may run concurrently,
Creating and Executing 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.
Week Fourteen Agenda Announcements Final Exam True/False -100 questions (1 point per question) Multiple Choice - 40 questions (2 points per question)
Agenda  Working with Processes: Purpose Running Programs within same process (execl, execlp, execle, execv, execvp, execve) “Spawning” other process (fork,
Scis.regis.edu ● CS 468: Advanced UNIX Class 4 Dr. Jesús Borrego Regis University 1.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. C H A P T E R S I X Exception Handling.
System calls for Process management
Chapter 11 Process Management
Unix Process Model Simple and powerful primitives for process creation and initialization. fork syscall creates a child process as (initially) a clone.
Week Fourteen Agenda Announcements Final Exam True/False -100 questions (1 point per question) Multiple Choice - 40 questions (2 points per question)
Linux Processes Travis Willey Jeff Mihalik. What is a process? A process is a program in execution A process includes: –program counter –stack –data section.
Concurrent Processes Processes can concurrently run same program. Processes can concurrently run same program. Processes can start other processes. Processes.
Process Management CS3320 Spring Process A process is an instance of a running program. –Not the same as “program” or “processor” Process provides.
Operating Systems Process Creation
CS4315A. Berrached:CMS:UHD1 Process Management Chapter 6.
Signals and Signal Processing CIS 370 Lab 7 Umass Dartmouth.
Signals (Chap 10 in the book “Advanced Programming in the UNIX Environment”) Acknowledgement : Prof. Y. Moon at Kangwon Nat’l Univ.
UNIX Signals * POSIX-Defined Signals * Signaling Processes * Signal Mask * sigaction * kill and sigaction * alarm * Interval Timers * POSIX.1b Timers *
Interprocess Communication Mechanisms. IPC Signals Pipes System V IPC.
CSC Advanced Unix Programming, Fall, 2008 Welcome back to UNIX System Programming! Monday, September 22, class 5.
© 숙대 창병모 1 제 10 장 신호 (Signal). © 숙대 창병모 2 Contents 1. Signal Concepts 2. signal() 3. Interrupted System Calls 4. kill() /raise() 5. alarm() pause() 6.
Process Description and Control Chapter 3. Source Modified slides from Missouri U. of Science and Tech.
ACCESS CONTROL. Components of a Process  Address space  Set of data structures within the kernel - process’s address space map - current status - execution.
S -1 Processes. S -2 wait and waitpid (11.2) Recall from a previous slide: pid_t wait( int *status ) wait() can: (a) block; (b) return with status; (c)
System calls for Process management Process creation, termination, waiting.
Unix System Administration Controlling Processes Chapter 5.
CS241 Systems Programming Discussion Section Week 2 Original slides by: Stephen Kloder.
Slide 1 COMP 3438 System Programming UNIX Processes UNIX Processes (Chapters 2 & 3)
CS241 Systems Programming Discussion Section Week 2 Original slides by: Stephen Kloder.
Process Related System Calls By Neha Hulkoti & Kavya Bhat.
S ALVATORE DI G IROLAMO (TA) Networks and Operating Systems: Exercise Session 1.
Process Manipulation. Process Manipulation in UNIX Basic process manipulation: creation, program loading, exiting, … fork(), exec(), wait(), exit() Process.
UNIX signals.
Task Control: Signals and Alarms Chapter 7 and 8
Unix Process Management
제11장 프로세스 시스템 프로그래밍 2011 가을 숙명여대 창병모.
Processes A process is a running program.
UNIX PROCESSES.
Structure of Processes
CSC Advanced Unix Programming, Fall 2015
Operating Systems Lecture 12.
제11장 프로세스 관리.
Inter-Process Communication ENCE 360
Process Control B.Ramamurthy 2/22/2019 B.Ramamurthy.
Task Control: Signals and Alarms Chapter 7 and 8
Unix Process Control B.Ramamurthy 4/11/2019 B.Ramamurthy.
Process Description and Control in Unix
Process Description and Control in Unix
System Programming: Process Management
Presentation transcript:

scis.regis.edu ● CS 468: Advanced UNIX Class 5 Dr. Jesús Borrego Regis University 1

Topics Midterm review Systems Programming Process Management Homework 3 Q&A 2

Process Management First process is init Process are created by processes ▫Calling fork() ▫One of few calls that return twice Child process inherits parent’s process table entries, except for PID, PPID, and running times Call to fork returns the PID of the child process to the parent and 0 to the child Best practice is to test the return of fork() 3

First Processes PID 0 (sched) – created at boot PID 0 executes fork and exec twice to create processes 1 (init) and 2 (pageout) 4 Process 1 fork/exec process 48 process 12 process 34 fork/exec

Process States 5 RunningZombiedRunnableIdle Sleeping Suspended Initialize Signal Exit Wait on Event Occurs Allocated CPU

Parent process A process creates a child process Parent waits until children processes terminate He return code from the child is passed to the parent to take appropriate action If the parent process terminates unexpectedly, all its children processes are inherited by init When a child terminates, it waits to die until parent acknowledges its termination 6

Unix process-oriented system calls fork – duplicates a process getpid – obtains process ID number getppid – obtains parent process ID number exit – terminates a process wait – waits for child process exec – replaces the code, data, and stack of a process 7

New process with fork 8 The parent calls fork and two return from it ▫The parent and child continue to run the same code concurrently ▫Each has a different stack and data spaces If fork succeeds, it returns the PID of the child to the parent and returns 0 to the child If fork fails, it returns -1 and there is no child process created

Process IDs A process can get its process ID and parent ID ▫getpid = returns process ID ▫getppid = returns parent process ID See example program on page 475 in UPU You can try the program if you have a C/C++ compiler For cygwin, you can use g++ Some examples follow 9

Orphan program 10

Executing Orphan.c 11

Orphan processes If a parent dies before its children processes, init adopts them The original PPID becomes 1 (init) Note how the child inherits PPID after parent terminates 12

Basic fork 13

Compiling and running fork 14

Running fork multiple times 15

Executing other programs Can call other programs with exec When running exec, your process current image is replaced with the program’s image When calling a program, your current process never terminates ▫It is replaced by the called program 16

Exec program 17

Compile and run program 18

Explanation Displays message on the screen Calls one of exec function ▫execl means to pass an argument ▫execlp means to search the path First argument is the program to run The rest of the parameters are passed to the programs as arguments (argv) ▫argv[0] is the name of the program (duplicated) ▫argv[1] is the directory list ▫argv[2] null pointer – end of arguments 19

Exec family of programs Exec followed by one or more characters ▫e = array of pointes to variables ▫l = command line ▫p = use PATH variable ▫v = command line arguments passes as array of pointers Arguments (arv[x]): ▫0 – name of program ▫Rest depend on the program being executed 20

Notes on executed program New program inherits no code or data from current process Signals and signal handlers are cleared Security information and PID of process are retained ▫Including UID of owner ▫File descriptors remain open and available to new program 21

Child process clean up If parent terminates right away, no problem If parent continues to execute and the child exits, parent must clean up ▫Or zombie processes hang around 22

Zombie example 23

Zombie run 24

Waiting for a child 25

Executing mywait 26

Waiting for a process to continue When we exec a program, the original process is no longer active How does the shell remain active when we execute commands? We want the shell to remain dormant while the command executes and then we want to return to the shell 27

Exec and Wait – first part 28

Exec and wait – main 29

Exec and wait – aux functions 30

Exec and wait run 31

What happened? The code invokes the shell in the child ▫PS1 sets the prompt for the shell The child invokes the shell We get interactive access to the shell while the child waits When we exit, we return to the child, and the child exits Parent notices child exited and then parent exits Parent is blocked until child is done 32

Other programs myexec.c – pp chdir.c - pp nice.c pp background.c – pp

Signals Sometimes called interrupts Called when unexpected things happen: ▫Floating point errors ▫Power failures ▫Alarm clock ‘ring’ ▫Death of child process ▫User termination ▫User suspend request Signal handler is called to act on it 34

Signals 1 – SIGHUP: hangup 2 – SIGINT: interrupt 3 – SIGQUIT: quit 4 – SIGILL: invalid instruction 5 – SIGTRAP: trace trap 6 – SIGABRT: abort 7 – SIGEMT: emulator trap instruction 8 – SIGFPE: arithmetic exception 9 – SIGKILL: kill 35

Signals (Cont’d) 10 – SIGBUS: bus error 11 – SIGSEGV: segmentation violation 12 – SIGSYS: bad argument to system call 13 – SIGPIPE: write on pipe and no reader 14 – SIGALRM: alarm clock 15 – SIGTERM: software termination 16/17 – SIGUSR1/1: user signal 1/2 18 – SIGCHLD: child status changed 19 – SIGPWR: power fail or restart 36

Signals (Cont’d) 20 – SIGWINCH: window size changed 21 – SIGURG: urgent socket condition 22 – SIGPOLL: pollable event 23 – SIGSTOP: stopped (signal) 24 – SIGSTP: stopped (user) 25 – SIGCONT: continued 26/27 – SIGTTIN/SIGTTOU: stopped (in/out) 28 – SIGVTALRM: virtual timer expired 29 – SIGPROF: profiler timer expired 30/31 – SIGXCPU/SIGFSZ: CPU/File limit exceeded 37

Suspend/ Resume Processes UPU pp

Suspend/ Resume Processes (Cont’d) UPU pp

Pulse.exe 40

Control Terminals - terminates a process and its children Every process is a member of a process group When a process forks, children inherit its process group from its parent Every process has a control terminal – the process where the process was started When - is detected, the terminal sends the signal to all processes in the process group 41

Pipe example (p.505) 42

Pipe example (Cont’d) 43

Pipe execution 44

Questions? 45