UNIX PROCESSES.

Slides:



Advertisements
Similar presentations
Process Management.
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.
CS 311 – Lecture 14 Outline Process management system calls Introduction System calls  fork()  getpid()  getppid()  wait()  exit() Orphan process.
Exec function Exec function: - replaces the current process (its code, data, stack & heap segments) with a new program - the new program starts executing.
Advanced OS Chapter 3p2 Sections 3.4 / 3.5. Interrupts These enable software to respond to signals from hardware. The set of instructions to be executed.
Process Control in Unix Operating Systems Hebrew University Spring 2004.
CSSE Operating Systems
CSE 451 Section 4 Project 2 Design Considerations.
Advanced Programming in the UNIX Environment Hop Lee.
Fork and Exec Unix Model Tutorial 3. Process Management Model The Unix process management model is split into two distinct operations : 1. The creation.
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
Copyright ©: Nahrstedt, Angrave, Abdelzaher1 Processes Tarek Abdelzaher Vikram Adve.
Fundamentals CIS 552. Fundamentals Low-level I/O (read/write using system calls)  Opening/Creating files  Reading & Writing files  Moving around in.
Introduction to Processes CS Intoduction to Operating Systems.
Today’s Topics Introducing process: the basic mechanism for concurrent programming –Process management related system calls Process creation Process termination.
Creating and Executing Processes
More on UART Interrupts; System Calls Reference on Interrupt Identification Register(IIR) slide 17 of
Process Control Process identifiers Process creation fork and vfork wait and waitpid Race conditions exec functions system function.
System calls for Process management
Unix Process Model Simple and powerful primitives for process creation and initialization. fork syscall creates a child process as (initially) a clone.
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.
Copyright ©: Nahrstedt, Angrave, Abdelzaher1 Processes and Threads.
Concurrent Processes Processes can concurrently run same program. Processes can concurrently run same program. Processes can start other processes. Processes.
Operating Systems Process Creation
CS4315A. Berrached:CMS:UHD1 Process Management Chapter 6.
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.
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.
Tutorial 3. In this tutorial we’ll see Fork() and Exec() system calls.
System calls for Process management Process creation, termination, waiting.
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.
4.1 Operating Systems Lecture 9 Fork and Exec Read Ch
Process Related System Calls By Neha Hulkoti & Kavya Bhat.
Linux/UNIX Programming APUE (Process Control) 문양세 강원대학교 IT 대학 컴퓨터과학전공.
Protection of System Resources
Using Processes.
Unix Process Management
Processes A process is a running program.
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
Structure of Processes
Lecture 5: Process Creation
More on UART Interrupts; System Calls
Fork and Exec Unix Model
System Structure B. Ramamurthy.
LINUX System Programming with Processes (additional)
System Structure and Process Model
Process Creation Process Termination
Tutorial 3 Tutorial 3.
Operation System Program 1
The Environment of Unix Process
Process Control B.Ramamurthy 2/22/2019 B.Ramamurthy.
Controlling Processes
Lecture 6: Multiprogramming and Context Switching
Unix Process Control B.Ramamurthy 4/11/2019 B.Ramamurthy.
Process Description and Control in Unix
EECE.4810/EECE.5730 Operating Systems
Process Description and Control in Unix
EECE.4810/EECE.5730 Operating Systems
System Programming: Process Management
Presentation transcript:

UNIX PROCESSES

What is a Unix Process An entity that executes a given piece of code has its own execution stack its own set of memory pages its own file descriptors table a unique process ID

Re-entrancy The ability to have the same function (or part of a code) being in some phase of execution, more than once at the same time. two or more processes try to execute this piece of code at the same time with a multi-process code, we don't have conflicts of variables, because normally the data section of each process is separate from that of other processes (so process A that runs program P and process B that runs the same program P, have distinct copies of the global variable 'i' of that program)

Process Creation The fork() system call is the basic way to create a new process. It is also a very unique system call, since it returns twice(!) to the caller.

fork()‏ This system call causes the current process to be split into two processes - a parent process, and a child process. All of the memory pages used by the original process get duplicated during the fork() call, so both parent and child process see the exact same image.

fork() (contd.)‏ The only distinction is when the call returns. When it returns in the parent process, its return value is the process ID (PID) of the child process. When it returns inside the child process, its return value is '0'. If for some reason this call failed (not enough memory, too many processes, etc.), no new process is created, and the return value of the call is '-1'. In case the process was created successfully, both child process and parent process continue from the same place in the code where the fork() call was used.

fork() Example Adress of the example

Note fork() copies also a memory area known as the 'U Area' (or User Area). This area contains, amongst other things, the file descriptor table of the process. This means that after returning from the fork() call, the child process inherits all files that were open in the parent process. If one of them reads from such an open file, the read/write pointer is advanced for both of them. On the other hand, files opened after the call to fork() are not shared by both processes. Further more, if one process closes a shared file, it is still kept open in the other process.

Child Process Termination there are two possibilities the parent process exits before the child the child exits before the parent

Child exits before parent When a child process exits, it is not immediately cleared off the process table. Instead, a signal is sent to its parent process, which needs to acknowledge it's child's death, and only then the child process is completely removed from the system. In the duration before the parent's acknowledgment and after the child's exit, the child process is in a state called "zombie".

The wait() System Call The simple way of a process to acknowledge the death of a child process is by using the wait() system call. When wait() is called, the process is suspended until one of its child processes exits, and then the call returns with the exit status of the child process. If it has a zombie child process, the call returns immediately, with the exit status of that process.

Parent exits before child When a process exits (terminates), if it had any child processes, they become orphans. An orphan process is automatically inherited by the 'init' process (process number 1 on normal Unix systems), and becomes a child of this 'init' process. This is done to ensure that when the process terminates, it does not turn into a zombie, because 'init' is written to properly acknowledge the death of its child processes.

Asynchronous Child Death Notification When a child process dies, a signal, SIGCHLD (or SIGCLD) is sent to its parent process. using a proper signal handler, the parent will get an asynchronous notification, and then when it'll call wait(), the system assures that the call will return immediately, since there is already a zombie child. pid t waitpid (pid t pid, int *status, int options);

Asynchronous Child Death Notification Example Adress of the example

execve system call allows a process to run a new program #include <unistd h> int execve (const char *pathname, const char *argv [], const char *envp[]); triggers the execution of a new program

execve (contd.)‏ pathname specifies the name of the file to be executed The parameter argv should point to a string of characters representing an argument The parameter envp specifies the variables in the program environment Each of the elements should contain the address of a character string of the form “name_of_variable=value”