Tutorial: The Programming Interface

Slides:



Advertisements
Similar presentations
3.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Process An operating system executes a variety of programs: Batch system.
Advertisements

CSE 451: Operating Systems Winter 2006 Module 4 Processes Ed Lazowska Allen Center 570.
1 Processes Professor Jennifer Rexford
1 Processes and Pipes COS 217 Professor Jennifer Rexford.
Processes CSCI 444/544 Operating Systems Fall 2008.
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 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.
Operating Systems Processes (Ch 4.1). Processes “A program in execution” Modern computers allow several at once –“pseudoparallelism” A B C Program Counter.
CSSE Operating Systems
Unix & Windows Processes 1 CS502 Spring 2006 Unix/Windows Processes.
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. Process Concept Process – a program in execution Textbook uses the terms job and process almost interchangeably A process includes: – program.
The Programming Interface. Main Points Creating and managing processes – fork, exec, wait Performing I/O – open, read, write, close Communicating between.
Lecture Topics: 11/3 Address spaces Memory protection Creating a process –NT style –Unix style.
Programming Interface. Main Points Process Concept Creating and managing processes – fork, exec, wait Communicating between processes Example: implementing.
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.
Multiprogramming CSE451 Andrew Whitaker. Overview Multiprogramming: Running multiple programs “at the same time”  Requires multiplexing (sharing) the.
Processes and Threads CS550 Operating Systems. Processes and Threads These exist only at execution time They have fast state changes -> in memory and.
Creating and Executing Processes
ITEC 502 컴퓨터 시스템 및 실습 Chapter 2-1: Process Mi-Jung Choi DPNM Lab. Dept. of CSE, POSTECH.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 3: Processes.
System calls for Process management
CS 153 Design of Operating Systems Spring 2015 Lecture 5: Processes and Threads.
Operating Systems Process Creation
CS4315A. Berrached:CMS:UHD1 Process Management Chapter 6.
1 Lecture 6 Introduction to Process Management COP 3353 Introduction to UNIX.
Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, Operating System Concepts Operating Systems Lecture 14 Threads 2 Read Ch.
Fall 2002 CS 325 Class Notes Page 1 Lecture 25 Today –exec() in Unix –CreateProcess in Windows Announcements.
Processes, Threads, and Process States. Programs and Processes  Program: an executable file (before/after compilation)  Process: an instance of a program.
Process Management Azzam Mourad COEN 346.
InterProcess Communication. Interprocess Communication Processes within a system may be independent or cooperating Cooperating process can affect or be.
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.
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.
4.1 Operating Systems Lecture 9 Fork and Exec Read Ch
Chapter 3 The Programming Interface Chien-Chung Shen CIS/UD
A process is a program in execution A running system consists of multiple processes – OS processes Processes started by the OS to do “system things” –
Introduction to Operating Systems
Process API COMP 755.
Chapter 4: Threads.
Chapter 5: Threads Overview Multithreading Models Threading Issues
Unix Process Management
Process Creation Processes get created (and destroyed) all the time in a typical computer Some by explicit user command Some by invocation from other running.
Chapter 3: Processes.
Processes in Unix, Linux, and Windows
Processes in Unix, Linux, and Windows
Introduction to Operating Systems
Lecture 5: Process Creation
Fork and Exec Unix Model
Chapter 2: The Linux System Part 2
More examples How many processes does this piece of code create?
Processes in Unix, Linux, and Windows
Remote Process Explorer
Operating Systems Lecture 6.
2/25/08 Frans Kaashoek MIT OS abstractions 2/25/08 Frans Kaashoek MIT
Tutorial 3 Tutorial 3.
Operating Systems Processes (Ch 4.1).
Jonathan Walpole Computer Science Portland State University
Lecture 6: Multiprogramming and Context Switching
October 7, 2002 Gary Kimura Lecture #4 October 7, 2002
CSE 451: Operating Systems Winter 2003 Lecture 4 Processes
Processes in Unix, Linux, and Windows
Processes in Unix and Windows
CS510 Operating System Foundations
CSE 451: Operating Systems Autumn 2004 Module 4 Processes
Presentation transcript:

Tutorial: The Programming Interface SE350: Operating Systems Tutorial: The Programming Interface

Main Points Creating and managing processes fork, exec, wait Example: implementing a shell

Shell A shell is a job control system Example: to compile a C program Allows programmer to create and manage a set of programs to do some task Windows, MacOS, Linux all have shells Example: to compile a C program cc –c sourcefile1.c cc –c sourcefile2.c ln –o program sourcefile1.o sourcefile2.o

Windows CreateProcess System call to create new process to run a program Create and initialize process control block (PCB) in kernel Create and initialize a new address space Load the program into the address space Copy arguments into memory in the address space Initialize hardware context to start execution at “start” Inform the scheduler that the new process is ready to run

Windows CreateProcess API (simplified) if (!CreateProcess( NULL, // No module name (use command line) argv[1], // Command line NULL, // Process handle not inheritable NULL, // Thread handle not inheritable FALSE, // Set handle inheritance to FALSE 0, // No creation flags NULL, // Use parent's environment block NULL, // Use parent's starting directory &si, // Pointer to STARTUPINFO structure &pi ) // Pointer to PROCESS_INFORMATION structure ) Ok, pretty complex! But its because there are a lot of aspects to a process

UNIX Process Management UNIX fork System call (without any arguments) to create a copy of the current process, and start it running UNIX exec System call to change the program being run by the current process UNIX wait System call to wait for a process to finish UNIX signal System call to send a notification to another process (e.g. SIGKILL, SIGINT) UNIX splits creating a process into two steps, each of them a lot simpler.

UNIX Process Management How is this used – typically, fork a process, child and parent are now both running the same program. One sets up the child program, and runs exec – becoming the new program The parent, usually, waits for the child to finish

Question: What Does This Code Print? int child_pid = fork(); if (child_pid == 0) { // I'm the child process printf("I am process #%d\n", getpid()); return 0; } else { // I'm the parent process printf("I am parent of process #%d\n", child_pid); } Parent could print first, or child could print first – you don’t know! Possible output: I am parent of process 495 I am process 495 Another less likely but still possible output: I am process 456 I am parent of process 456

Questions Can UNIX fork() return an error? Why? Can UNIX exec() return an error? Why? Can UNIX wait() ever return immediately? Why?

Implementing UNIX fork Steps to implement UNIX fork Create and initialize the process control block in kernel Create a new address space Initialize the address space with a copy of the entire contents of the address space of the parent Inherit the execution context of the parent E.g., any open files Inform the scheduler that the new process is ready to run

Implementing UNIX exec Steps to implement UNIX exec Load the program into the current address space Copy arguments into memory in the address space Initialize the hardware context to start execution at “start”

Implementing a Shell char *prog, **args; int child_pid; // Read and parse the input a line at a time while (readAndParseCmdLine(&prog, &args)) { child_pid = fork(); // create a child process if (child_pid == 0) { exec(prog, args); // I'm the child process. Run program // NOT REACHED } else { wait(child_pid); // I'm the parent, wait for child return 0; }

Acknowledgment This lecture is a slightly modified version of the one prepared by Tom Anderson