Unix Process Management

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

1 CS345 Operating Systems Φροντιστήριο Άσκησης 1.
15-213, Fall 06 Outline Shell Lab Processes Signals.
15-213/ Intro to Computer Systems by btan with reference to Spring 10’s slides.
Process Control Hua LiSystems ProgrammingCS2690Process Control Page 1 of 41.
UNIX Process Control Bach 7 Operating Systems Course Hebrew University Spring 2007.
Process in Unix, Linux and Windows CS-3013 C-term Processes in Unix, Linux, and Windows CS-3013 Operating Systems (Slides include materials from.
CS-502 Fall 2006Processes in Unix, Linux, & Windows 1 Processes in Unix, Linux, and Windows CS502 Operating Systems.
CSSE Operating Systems
Unix & Windows Processes 1 CS502 Spring 2006 Unix/Windows Processes.
Processes, Signals, I/O, Shell lab
Fork and Exec Unix Model Tutorial 3. Process Management Model The Unix process management model is split into two distinct operations : 1. The creation.
Processes in Unix, Linux, and Windows CS-502 Fall Processes in Unix, Linux, and Windows CS502 Operating Systems (Slides include materials from Operating.
Process Control. Major Requirements of an Operating System Interleave the execution of several processes to maximize processor utilization while providing.
BINA RAMAMURTHY UNIVERSITY AT BUFFALO System Structure and Process Model 5/30/2013 Amrita-UB-MSES
The Programming Interface. Main Points Creating and managing processes – fork, exec, wait Performing I/O – open, read, write, close Communicating between.
Process in Unix, Linux, and Windows CS-3013 A-term Processes in Unix, Linux, and Windows CS-3013 Operating Systems (Slides include materials from.
Today’s Topics Introducing process: the basic mechanism for concurrent programming –Process management related system calls Process creation Process termination.
1 Week 2 The Crunchy Shell to the Soft and Chewy Kernel… Sarah Diesburg 8/3/2010 COP4610 / CGS5765.
Creating and Executing Processes
ITEC 502 컴퓨터 시스템 및 실습 Chapter 2-1: Process Mi-Jung Choi DPNM Lab. Dept. of CSE, POSTECH.
8-Sep Operating Systems Yasir Kiani. 8-Sep Agenda for Today Review of previous lecture Process scheduling concepts Process creation and termination.
Process Control Process identifiers Process creation fork and vfork wait and waitpid Race conditions exec functions system function.
System calls for Process management
Operating Systems Processes 1.
Scis.regis.edu ● CS 468: Advanced UNIX Class 5 Dr. Jesús Borrego Regis University 1.
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.
Operating Systems Process Creation
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,
Process Management Azzam Mourad COEN 346.
1 A Seven-State Process Model. 2 CPU Switch From Process to Process Silberschatz, Galvin, and Gagne  1999.
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)
Tutorial 3. In this tutorial we’ll see Fork() and Exec() system calls.
System calls for Process management Process creation, termination, waiting.
Direct memory access. IO Command includes: buffer address buffer length read or write dada position in disk When IO complete, DMA sends an interrupt request.
CS241 Systems Programming Discussion Section Week 2 Original slides by: Stephen Kloder.
1 Unix system calls fork( ) wait( ) exit( ). 2 How To Create New Processes? n Underlying mechanism -A process runs fork to create a child process -Parent.
CS241 Systems Programming Discussion Section Week 2 Original slides by: Stephen Kloder.
Process Related System Calls By Neha Hulkoti & Kavya Bhat.
Protection of System Resources
Using Processes.
Chapter 3: Processes.
Processes A process is a running program.
Processes in Unix, Linux, and Windows
UNIX 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.
Tarek Abdelzaher Vikram Adve Marco Caccamo
System Structure and Process Model
System Structure and Process Model
Processes in Unix, Linux, and Windows
CGS 3763 Operating Systems Concepts Spring 2013
Lecture 5: Process Creation
Fork and Exec Unix Model
System Structure B. Ramamurthy.
LINUX System Programming with Processes (additional)
Processes in Unix, Linux, and Windows
System Structure and Process Model
Operating Systems Lecture 6.
Process Creation Process Termination
Tutorial 3 Tutorial 3.
Tutorial: The Programming Interface
Process Control B.Ramamurthy 2/22/2019 B.Ramamurthy.
Unix Process Control B.Ramamurthy 4/11/2019 B.Ramamurthy.
Processes in Unix, Linux, and Windows
Processes in Unix and Windows
Process Description and Control in Unix
Process Description and Control in Unix
System Programming: Process Management
Presentation transcript:

Unix Process Management Processes Unix Process Management Advise students to download the code from the Code/createProcesses directory.

Unix Process Creation Parents create children Resource sharing results in a tree of processes Resource sharing Parent and children share all resources Children share subset of parent’s resources Parent and child share no resources Execution Parent and children execute concurrently Parent waits until children terminate

Unix Process Creation Address space UNIX examples Child duplicate of parent Child has a program loaded into it UNIX examples fork system call creates new process exec family of system calls used after a fork to replace the process’ memory space with a new program

Unix Process Hierarchies

Unix Process Hierarchies Process Group A process and all of its descendants which have not changed the default process group ID ( via setpgid(2) ) User sends signal from keyboard Signal delivered to all members of process group associated with keyboard Each process can: Catch signal, ignore signal, terminate (default action) The init process: root parent of all user processes Windows doesn’t enforce a hierarchy

Sending Signals to Processes Command Line e.g., “kill –STOP 1899” Send SIGSTOP signal (19) to process 1899 Process e.g., “rc = kill( 1899, SIGSTOP );” Keyboard (generated by terminal driver) Interrupt key (ctrl-c) Generates SIGINT; terminate process Signal sent to all processes in foreground process group Ctrl-c is the interrupt key

Sending Signals to Processes Quit key (ctrl-\) Generates SIGQUIT; terminate process with core dump Stop key (ctrl-z) Generates SIGSTP; stop process (can be resumed) SIGSTP (interactive stop) is different from SIGSTOP Signal sent to all processes in foreground process group Ctrl-\ is the quit key

Unix Process Creation (fork) Reserve swap space for child’s data and stack Allocate new PID and proc structure Init child’s process control block (PCB) Copy UID, GID, and signal masks from parent Reset (zero) statistics Copy parent’s registers to child’s hardware context Setup virtual memory tables See http://www.linuxjournal.com/article/6483 for a discussion of proc structure fork() is called once but returns twice (in the child and in the parent).

Unix Process Creation (fork) Mark child runnable and give to scheduler Return PID = 0(zero) to child Return child PID to parent Effects of fork Child gets a copy of its parent’s memory BUT changes made by child are not reflected in parent EXCEPT a child can affect the I/O state of parent File descriptors can point to same file table entry WARNING: Parent should “fflush(stdout)” before fork if using printf() See Advanced programming in the Unix Environment, second edition, pages 212, 213.

Example int main(){ { pid_t child_pid; int x = 3, y = 4; child_id = fork(); //Two processes //Code that the child process will execute if(child_id == 0){ x = 7; printf(“The value of x in the child process is %d\n”, x); } else { //Code that the parent process will execute printf(“The value of x in the parent process is %d\n”,x); //Common code printf(“I am done\n”); return 0;

exec Functions Use to overlay process image with new program Begins executing at its main() function Process ID does not change Six exec functions: execl execv execle execve execlp execvp Argument[0] is, as a convention, the name of the executable file, but could be anyting. l  list of arguments v  argv[] vector P  file name E  envp[] vector instead of inheriting environment of parent

Examples execlp("./myCopy", "myCopy", argv[1], argv[2], NULL); execv("./myCopy", argv);

exec Operations Find executable file (argv[0]) Verify that user may exec file Check that file header is a valid executable Copy exec args and env variables to kernel space Current user space will be destroyed Allocate heap and stack and free old process space Setup new address space Copy exec args and env variables into new space Reset all signal handlers Initialize hardware context

Process termination Termination Condition Normal exit (see exit(3) and _exit(2)) Error exit Fatal error (e.g., illegal instr, bad addr, divide by zero) Killed by another process (kill system call) exit(3) is a function in the standard C library _exit(2) is a system call

waitpid pid_t waitpid(pid_t pid, int *status, int options); pid values Unlike wait(2), waitpid doesn’t have to block wait(2) blocks until one of its children terminates pid values pid == -1: Wait for any child to terminate pid > 0: Wait for child whose PID equals pid pid == 0: Wait for any child whose PGID equals the PGID of process pid pid < -1: Wait for any child whose PGID = abs(pid) Returns process ID id if OK, returns -1 if error, returns 0 (see later)

waitpid *status Contains exit status, signal number, and flags WIFEXITED(status) True if child terminated normally Ex: printf(“exit = %d\n”, WEXITSTATUS(status));

waitpid options options = 0 options = WNOHANG No special handling Don’t block if child is not available and return 0 Ex: rc = waitpid(pid, &status, WNOHANG); if (rc == -1) { . . . error . . . } else if (rc == 0) { . . . no child available . . .} else { . . . rc should equal pid . . . }