Operating Systems. Processes
|
|
- Rolf Gregory
- 6 years ago
- Views:
Transcription
1 Operating Systems Processes 1
2 Process Concept Process a program in execution; process execution progress in sequential fashion
3 Program vs. Process Program is passive entity stored on disk (executable file), process is active Program becomes process when executable file loaded into memory Execution of program started via GUI mouse clicks, command line entry of its name, etc One program can be several processes Consider multiple users executing the same program
4 Process Context/Image Consists of The address space of the process The program code, also called text section Stack containing temporary data run-time stack of activation records (function parameters, return addresses, local variables) Data section containing global variables, statics, and constants Heap containing memory dynamically allocated during run time
5 Process Context/Image And process current activity Current values of registers: general registers, PC, SP, PSW, segmentation registers (limit, base) Other information: open files table, status of ongoing I/O process status (running, ready, blocked), user id,... 5
6 Memory Memory Layout of a Process Stack Free space Heap data Code/Text CPU PSW Stack Pointer Program Counter 6
7 Process States (1) Three states a process may be in: 1. Running (actually using the CPU at that instant). 2. Ready (runnable; temporarily stopped to let another process run). 3. Blocked (unable to run until some external event happens). Tanenbaum & Bos, Modern Operating Systems: 4th ed., Global Edition (c) 2015 Pearson Education Limited. All rights
8 Process States (2) A process can be in running, blocked, or ready state. Transitions between these states are as shown. Tanenbaum & Bos, Modern Operating Systems: 4th ed., Global Edition (c) 2015 Pearson Education Limited. All rights reserved.
9 blocked state cat file1 file2 file3 grep test grep process is blocked (waits) until input is available from the pipe (output of cat is written to pipe) Or, a process may explicitly suspend itself pause()
10 Process Model The lowest layer of a process-structured operating system handles interrupts and scheduling. Above that layer are sequential processes. Tanenbaum & Bos, Modern Operating Systems: 4th ed., Global Edition (c) 2015 Pearson Education Limited. All rights reserved.
11 Context Switch A CPU can execute one process at a time In a multiprogramming environment the CPU switches from one process to another for brief periods of time. When CPU switches to another process, the system must save the state of the old process and load the saved state for the new process via a context switch Context of a process is represented in the Process control block
12 Keeping Track of Processes For each process, OS maintains a data structure, called the process control block (PCB). The PCB provides a way of accessing all information relevant to a process: This data is either contained directly in the PCB, or else the PCB contains pointers to other system tables. All current processes (PCBs) are stored in a system table called the process table. Either a linked list or an array, of PCB s. 12
13 Process Control Block(PCB) Some of the fields of a typical process table entry. Tanenbaum & Bos, Modern Operating Systems: 4th ed., Global Edition (c) 2015 Pearson Education Limited. All rights reserved.
14 Process Representation in Linux Represented by the C structure task_struct pid t_pid; /* process identifier */ long state; /* state of the process */ unsigned int time_slice /* scheduling information */ struct task_struct *parent; /* this process s parent */ struct list_head children; /* this process s children */ struct files_struct *files; /* list of open files */ struct mm_struct *mm; /* address space of this process */
15 Process Scheduling Process scheduler selects among available processes for next execution on CPU Maintains scheduling queues of processes Job queue set of all processes in the system Ready queue set of all processes residing in main memory, ready and waiting to execute Device queues set of processes waiting for an I/O device
16 When are processes created? System initialization many daemons(background processes) for processing , printing, web pages etc. Shell (foreground) Execution of a process creation system call by a running process (fork or CreateProcess) User request to create a new process (type a command or click an icon) List of all active processes: ps (Unix), Ctl-Alt-Del (Windows) 16
17 When are processes terminated? Normal exit (voluntary) Done its job exit() in UNIX, ExitProcess() in Windows, GUI based Error exit (voluntary) Process discovers a fatal error itself and exits with an error code E.g. cp file1 file2, when file1 does not exist Fatal error (involuntary), due to bugs E.g. divide by zero, referencing illegal memory Killed by another process (involuntary) By executing kill(..) system call in Unix Killer process needs authorization (e.g. the root) 17
18 Creating processes in UNIX A Unix process is created by another. a newly created process is the child of the parent process that created it every process has exactly one parent a process may create any number of child processes processes have a unique PID (process ID) index to the PCB in the process table Processes are created in UNIX with the fork() system call. 18
19 Process Hierarchies Processes form a hierarchy UNIX calls this a process group Signals can be sent to all processes of a group Windows has no concept of process hierarchy all processes are created equal 19
20 init At the root of the family tree of processes is the special process init: created as part of the bootstrapping procedure pid = 1 among other things, init spawns a child to listen to each terminal, so that a user may log on (login processes). If login successful, executes a shell to start accepting commands do "man init to learn more about it 20
21 A typical tree of processes in Linux init pid = 1 login pid = 8415 kthreadd pid = 2 sshd pid = 3028 bash pid = 8416 khelper pid = 6 pdflush pid = 200 sshd pid = 3610 ps pid = 9298 emacs pid = 9204 tcsch pid = 4005
22 Process Control To list the complete information for all active processes in the system ps ef To list your processes ps
23 Process Control When the shell has to wait for a process to finish before giving you another prompt, that process is in the foreground A background process is one that runs independently of the parent shell The shell doesn't have to wait for the process to finish The shell gives you a prompt immediately and you can execute another command To run a command in the background: command & The shell will display the job number and PID of the background process and then display the prompt Any output of the background process that is sent to stdout will appear on the terminal, intermixed with the foregound process you will probably want to redirect the process output
24 Process Control When a process is in the background, you can't use <ctrl>c to stop it Only foreground processes will recognize keyboard input You must use the kill command kill <pid> If the kill command is ignored, then use the -9 option kill -9 <pid> We can control whether a process should continue in the foreground or background From background to foreground fg <job number> From foreground to background <ctrl>z to suspend the foreground process bg to send it to the background If a background process needs input, the shell will stop the job You must then bring it to the foreground to enter the input
25 Creating a process in UNIX We need some mechanism to instruct the system to create a new process fork system call When fork( ) is used, the OS generates a copy of the calling process The original process is the parent process The copy is the child process Execution in the two IDENTICAL processes continues from the point of the fork( ) The child process inherits all variables, values, open files, current directory, environment variables, etc. from the parent The child is assigned a unique PID The parent's fork returns the child's PID The child's fork returns 0 There is no guarantee which process, parent or child, will enter the CPU first
26 fork() pid = fork() if (pid!=0) { //parent code} else { // child code }
27 fork() example: fork_ex1.c #include <stdio.h> #include <unistd.h> main() { int pid; printf("i am the original process with PID %d and PPID %d.\n", getpid(), getppid()); pid = fork(); /* child and parent continue from here */ if (pid!= 0) { /* parent code */ printf("i am the parent process with PID %d and PPID %d.\n", getpid(), getppid()); printf("my child's PID is %d\n", pid); } else { /* child code */ printf("i am the child process with PID %d and PPID %d.\n", getpid(), getppid()); } } printf("pid %d terminates.\n", getpid());
28 output > g++ -o ex1 fork_ex1.c >./ex1 I am the original process with PID and PPID I am the parent process with PID and PPID my child's PID is PID terminates. I am the child process with PID and PPID PID terminates.
29 getpid, getppid, getpgid, setpgid pid_t getpid() Returns the PID of the calling process pid_t getppid() Returns the calling process parent s PID If parent needs child processes PIDs they must be saved when the children are forked. Process groups Every process belongs to a group The parent process is the process leader of all its children processes The leader's pid will also be the process group id (PGID) The PGID allows the OS to send signals to groups of processes pid_t getpgid(pid_t pid); Returns the process group ID of the process whose PID is equal to pid Returns the process group ID of the calling process if pid is 0 int setpgid(pid_t pid, pid_t pgid); Sets the process group ID of the process with PID pid to pgid
30 fork_ex2.c /* count the number of hees, has and hos */ /* then remove newline characters try again */ #include <stdio.h> #include <sys/types.h> #include <unistd.h> main() { } fork(); printf("hee\n"); fork(); printf("ha\n"); fork(); printf("ho\n");
31 Output (with newline, output not buffered) > g++ -o ex2 fork_ex2.c >./ex2 hee ha hee ho ha ha ha ho ho ho ho ho ho ho >
32 Output without newline (buffered) Buffer is flushed when full, or when file is closed. newline forces flush to stdout Buffers are inherited by child process Output: heehahoheehahoheehahoheehahoheehahoheehahoheehahoheehaho
33 Open files Every process is given a file descriptor table Every open file of a process is assigned an index into this table called the file descriptor When a child process is forked, it receives a COPY of its parent's file descriptor table This includes where the parent is in each open file The file pointer offset That is, the child starts reading from the same point If one of them reads from a such an open file, the read/write pointer is advanced for both of them.
34 Getting file Information int stat(const char *filename, struct stat *buf) int stat(int filedes, struct stat *buf) Returns the information for the given filename/file descriptor in the stat struct The stat struct: struct stat { mode_t st_mode; /* Protection */ ino_t st_ino; /* Inode number */ dev_t st_dev; /* ID of device containing */ /* a directory entry for this file */ nlink_t st_nlink; /* Number of links */ uid_t st_uid; /* User ID of the file's owner */ gid_t st_gid; /* Group ID of the file's group */ off_t st_size; /* File size in bytes */ time_t st_atime; /* Time of last access */ time_t st_mtime; /* Time of last data modification */ time_t st_ctime; /* Time of last file status change */ /* Times measured in seconds since */ /* 00:00:00 UTC, Jan. 1, 1970 */ long st_blksize; /* Preferred I/O block size */ blkcnt_t st_blocks; /* Number of 512 byte blocks allocated*/ }
35 #include <stdio.h> #include <sys/types.h> #include <sys/stat.h> #include <unistd.h> stat_ex.c main(int argc, char *argv[]) { struct stat buff; if (argc > 1 ) { if (stat(argv[1], &buff)!= -1) { printf("the size in bytes of %s is:", argv[1]); printf("%d\n", buff.st_size); } else { perror(argv[1]); return 1; } } else { printf("usage: %s filename\n", argv[0]); return 2; } return 0; //successful }
36 Handling error When a system call or library function fails, it usually returns a -1 It also assigns a value to an external variable errno By examining errno, you can determine the cause of the failure errno always contains the value of the last failed call A list of error values, their defined constants, and a short explanation of the error can be found in /usr/include/sys/errno.h To include this header file in your program, use #include <errno.h> perror system call Used to capture the description of any error It takes one argument - a pointer to a char (string s) It prints the string s followed by a colon and a blank, then an error message and a new line See errno_ex.c
37 Current Directory char *getcwd(char *buf, size_t size); The getcwd() function (not system call) copies an absolute pathname of the current working directory to the array pointed to by buf, which is of length size. If the current absolute path name would require a buffer longer than size elements, NULL is returned, and errno is set to ERANGE Going someplace new int chdir(const char *path); chdir changes the current directory to that specified in path. What do you think happens when a child process executes a chdir - does this effect the parent?
38 /* */ Testing the chdir() function #include <stdio.h> #include <unistd.h> #include <sys/param.h> main( ) { int pid; printf( "Before forking, my directory is: %s\n", getcwd(null, MAXPATHLEN+1) ); pid = fork(); if ( pid!= 0 ) { sleep( 5 ); printf( "Parent's directory is: %s\n", getcwd(null, MAXPATHLEN+1) ); } else { chdir( "/usr/include" ); printf( "child's directory is: %s\n", getcwd(null, MAXPATHLEN+1) ); } }
39 output >a.out Before forking, my directory is: /home/fatalay/csc310 child's directory is: /usr/include Parent's directory is: /home/fatalay/csc310
40 exec() When you use the shell to run a command (say ls), the shell will execute fork( ) to get a new process running How then does the shell get ls to run in the child process? The child process is just a copy of the shell - which is certainly NOT the ls utility Use an exec( ) system call or library function During an exec the current process image is overlaid with the command image The text, data, and stack segments are replaced with the new code Signals that were being caught in the original process are reset to their default action If successful, exec does NOT return since the original code is lost The new program begins executing at main (if a C, C++, or Java program)
41 exec family 5 library functions Execl, execlp, execv, execvp, execle 1 system call Execve All library functions call the system call execve execlp, execvp are the most commonly used.
42 execl and execlp execl library function int execl(const char *path, const char *arg0,...); path is the absolute or relative path name of the command arg0 the name of the command arg1 - argn are the null terminated strings representing arguments to the command argn must be NULL execlp library function int execlp(const char *file, const char *arg0,...); file is the absolute or relative path name of the command PATH will be searched if the first character is not a /
43 execv and execvp execv library function int execv(const char *path, char *const argv[]); path is the absolute or relative path name of the command argv is an array of pointers to null-terminated strings that represent the arguments to the command argv[0] should be the name of the command arg[n] must be NULL execvp library function int execvp(const char *file, char *const argv[]); file is the absolute or relative path name of the command PATH will be searched if the first character is not a /
44 execl() example #include <stdio.h> #include <unistd.h> main() { printf("i'm process %i and I'm about to exec an ls -l\n", getpid()); execl("/bin/ls", "ls", "-l", NULL); /* Execute ls */ printf("this line should never be executed.\n"); } >./execl_ex I am process 7168 and I am about to exec an ls -l total 44 -rw-r--r-- 1 fatalay sjufacul 506 Feb 16 23:12 chdir_ex.c -rwxr-xr-x 1 fatalay sjufacul 6492 Feb 16 23:48 execl_ex -rw-r--r-- 1 fatalay sjufacul 183 Feb 16 23:48 execl_ex.c -rw-r--r-- 1 fatalay sjufacul 563 Feb 10 00:11 fork_ex1.c
45 execvp example See execvp_ex.c #include <stdio.h> #include <unistd.h> main(int argc, char* argv[]) { fprintf(stdout, "Parent is about to fork child\n"); if (fork() == 0) /* child */ { fprintf(stdout, "Child process is about to exec\n"); execvp(argv[1], &argv[1]); /* execute other program */ fprintf(stderr, "This line should never print\n"); fprintf(stderr, "Could not execute %s\n", argv[1]); } fprintf(stdout, "Parent is about to terminate\n"); }
46 argv[1] Output >./execvp_ex ls -l Parent is about to fork child Parent is about to terminate Child process is about to exec > total 62 -rw-r--r-- 1 fatalay sjufacul 506 Feb 16 23:12 chdir_ex.c -rw-r--r-- 1 fatalay sjufacul 935 Feb 10 00:12 errno_ex.c -rwxr-xr-x 1 fatalay sjufacul 6572 Feb 16 23:52 execl_ex -rw-r--r-- 1 fatalay sjufacul 247 Feb 16 23:52 execl_ex.c -rwxr-xr-x 1 fatalay sjufacul 7136 Feb 17 15:22 execvp_ex -rw-r--r-- 1 fatalay sjufacul 1150 Feb 17 15:22 execvp_ex.c -rw-r--r-- 1 fatalay sjufacul 563 Feb 10 00:11 fork_ex1.c
47 Process Termination Process executes last statement and then asks the operating system to delete it using the exit() system call. void exit(int status) //include <stdlib.h> Returns status data from child to parent 0: success, nonzero: failure If parent is executing a wait(), it is notified of child s exit status is made available to parent If the parent is not waiting, the child's status will be made available to it when the parent subsequently executes wait( ) Process resources are deallocated by operating system Exit flushes all output streams and closes all open streams File descriptors are closed A SIGCHLD is sent to the parent process The PPID of all of its child processes is set to 1 (init)
48 Status It is stored as an integer Assuming a 32-bit integer: 0 0 exitcode 0 The high-order 16 bits are zero byte 3 byte 2 byte 1 byte 0 Normal termination Byte 1 contains the exit code (0-255) Byte 0 contains zeros Termination because of an un-caught signal Byte 1 contains zeros Byte 0 contains the signal number
49 wait() The wait( ) system call pid_t wait(int *status); Include: #include <sys/types.h> #include <sys/wait.h> This call will suspend the parent process until any of its child processes terminates Then the wait call returns and the parent process can continue The return value from wait Child is present - the terminating child's PID No child present - -1 If a process has one or more zombie children, wait returns immediately with the status of one of the zombies status is a pointer to a location that will receive the child's exit status information
50 wait_ex.c /* This program demonstrates the wait system call and the status returned by the child process */ #include <stdio.h> #include <stdlib.h> main() { int pid, status, childpid; } printf("i'm the parent process and my PID is %i\n", getpid()); pid = fork(); if (pid!= 0) /* parent */ { printf("i'm the parent process with PID %i and PPID %i\n, getpid(), getppid()); childpid = wait (&status); /* wait for child to terminate */ printf("a child with PID %i terminated with exit code %i\n, childpid, status >> 8); printf(" Parent - PID %i terminates\n", getpid()); } else { printf("i'm the child process with PID %i and PPID %i\n, getpid(), getppid()); printf(" Child - PID %i terminates\n", getpid()); exit( 15 ); }
51 Output I'm the parent process and my PID is I'm the parent process with PID and PPID I'm the child process with PID and PPID Child - PID terminates A child with PID terminated with exit code 15 Parent - PID terminates
52 How shell executes a command Parent shell fork wait exec Required job exit Child when you type a command, the shell forks a clone of itself the child process makes an exec call, which causes it to stop executing the shell to replace the process memory space with a new program the parent process, still running the shell, waits for the child to terminate 52
53 waitpid() waitpid( ) system call pid_t waitpid(pid_t pid, int *status, int options); pid specifies what to wait for pid > 0 Wait for child whose PID equals pid pid < -1 Wait for a child whose GID is equal to the absolute value of pid pid = -1 Wait for any child to finish - same behavior as wait( ) pid = 0 Wait for a child whose GID is the same as the calling process status is the same as for wait( )
54 waitpid() options allows you to specify that a call to waitpid( ) should not suspend the parent process if no child process is ready to report its exit status 0: don t care WNOHANG: return immediately if no child has exited- do not block if the status cannot be obtained, return a value of 0 not the PID The return value from waitpid The terminating child's PID returns -1 in case of failure, errno set to indicate the error. E.g. if errno is set to ECHILD, that means no child process
55 Example See waitpid_ex.c Output >./waitpid_ex I'm the parent process and my PID is I'm the parent process with PID and PPID I'm the first child process with PID and PPID I'm the second child process with PID and PPID Child2 - PID terminates Child1 - PID terminates A child with PID terminated with exit code 15 Parent - PID terminates
56 In previous example, do ps right after child 2 terminates, what do you see? Child 2 is a defunct (zombie) process
57 Zombies and Orphans When a child process exits, it is not immediately cleared off the process table Instead, a signal (SIGCHLD) is sent to its parent process The parent needs to acknowledge its child's death using a wait( ) system call Only then is the child process completely removed from the system In the time between the child's exit and the parent's acknowledgment, the child process is in a state called zombie When the parent process is not properly coded, the child remains in the zombie state A zombie process does not take up many resources, but it does use up a PID To see zombie proceses ps -ef grep defunct
58 Zombie process (from wikipedia) When a process ends, all of the memory and resources associated with it are deallocated so they can be used by other processes. However, the process's entry in the process table remains. The parent is sent a SIGCHLD signal indicating that a child has died; the handler for this signal will typically execute the wait system call, which reads the exit status and removes the zombie. The zombie's process ID and entry in the process table can then be reused. However, if a parent ignores the SIGCHLD, the zombie will be left in the process table.
59 Orphans When a process exits, if it had any child processes, they become orphans Who will then accept the child's SIGCHLD signal? An orphan process is automatically adopted by the init process (PID 1) and becomes a child of this init process Thus when the child terminates, it does not turn into a zombie init is properly written to acknowledge the death of its child processes
60 Example See zombie_ex.c Output >./zombie_ex & [1] > ps PID TTY TIME CMD pts/19 0:00 tcsh pts/19 0:00 csh pts/19 0:00 zombie_e pts/19 0:00 ps pts/19 0:00 zombie_e > ps -ef grep defunct fatalay :37:19 pts/19 0:00 grep defunct fatalay ? 0:00 <defunct> > kill > ps -ef grep defunct fatalay :37:38 pts/19 0:00 grep defunct parent
61 Avoiding zombies To avoid creating zombie processes, the parent must: 1. Handle the SIGCHLD signal. 2. In this signal handling function, the parent must wait for the child process. We will explore signals as an interprocess communications (IPC) mechanism shortly.
UNIX System Calls. Sys Calls versus Library Func
UNIX System Calls Entry points to the kernel Provide services to the processes One feature that cannot be changed Definitions are in C For most system calls a function with the same name exists in the
More informationCPSC 341 OS & Networks. Processes. Dr. Yingwu Zhu
CPSC 341 OS & Networks Processes Dr. Yingwu Zhu Process Concept Process a program in execution What is not a process? -- program on a disk A process is an active object, but a program is just a file It
More informationCS240: Programming in C
CS240: Programming in C Lecture 16: Process and Signals Cristina Nita-Rotaru Lecture 16/ Fall 2013 1 Processes in UNIX UNIX identifies processes via a unique Process ID Each process also knows its parent
More informationPROCESS MANAGEMENT. Operating Systems 2015 Spring by Euiseong Seo
PROCESS MANAGEMENT Operating Systems 2015 Spring by Euiseong Seo Today s Topics Process Concept Process Scheduling Operations on Processes Interprocess Communication Examples of IPC Systems Communication
More informationSystem Calls. Library Functions Vs. System Calls. Library Functions Vs. System Calls
System Calls Library Functions Vs. System Calls A library function: Ordinary function that resides in a library external to the calling program. A call to a library function is just like any other function
More informationCS 355 Operating Systems. Keeping Track of Processes. When are processes created? Process States 1/26/18. Processes, Unix Processes and System Calls
CS 355 Operating Systems Processes, Unix Processes and System Calls Process User types command like run foo at keyboard I/O device driver for keyboard and screen Command is parsed by command shell Executable
More informationUnix-Linux 2. Unix is supposed to leave room in the process table for a superuser process that could be used to kill errant processes.
Unix-Linux 2 fork( ) system call is successful parent suspended child created fork( ) returns child pid to parent fork( ) returns zero value to child; zero is the pid of the swapper/scheduler process both
More informationCSC 1600 Unix Processes. Goals of This Lecture
CSC 1600 Unix Processes q Processes Goals of This Lecture q Process vs. program q Context switching q Creating a new process q fork: process creates a new child process q wait: parent waits for child process
More informationPROCESSES. Jo, Heeseung
PROCESSES Jo, Heeseung TODAY'S TOPICS What is the process? How to implement processes? Inter-Process Communication (IPC) 2 WHAT IS THE PROCESS? Program? vs. Process? vs. Processor? 3 PROCESS CONCEPT (1)
More informationProcesses. Jo, Heeseung
Processes Jo, Heeseung Today's Topics What is the process? How to implement processes? Inter-Process Communication (IPC) 2 What Is The Process? Program? vs. Process? vs. Processor? 3 Process Concept (1)
More informationOperating System Structure
Operating System Structure CSCI 4061 Introduction to Operating Systems Applications Instructor: Abhishek Chandra Operating System Hardware 2 Questions Operating System Structure How does the OS manage
More informationLesson 2. process id = 1000 text data i = 5 pid = 1200
Lesson 2 fork: create a new process. The new process (child process) is almost an exact copy of the calling process (parent process). In this method we create an hierarchy structure for the processes,
More informationCSci 4061 Introduction to Operating Systems. Processes in C/Unix
CSci 4061 Introduction to Operating Systems Processes in C/Unix Process as Abstraction Talked about C programs a bit Program is a static entity Process is an abstraction of a running program provided by
More informationOperating systems and concurrency - B03
Operating systems and concurrency - B03 David Kendall Northumbria University David Kendall (Northumbria University) Operating systems and concurrency - B03 1 / 15 Introduction This lecture gives a more
More informationUnix Processes 1 / 31
Unix Processes 1/31 A Unix Process Instance of a program in execution. OS loads the executable in main-memory (core) and starts execution by accessing the first command. Each process has a unique identifier,
More informationProcesses. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University
Processes Jin-Soo Kim (jinsookim@skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu OS Internals User space shell ls trap shell ps Kernel space File System Management I/O
More informationChapter 3: Processes. Operating System Concepts 9 th Edit9on
Chapter 3: Processes Operating System Concepts 9 th Edit9on Silberschatz, Galvin and Gagne 2013 Chapter 3: Processes 1. Process Concept 2. Process Scheduling 3. Operations on Processes 4. Interprocess
More informationPrepared by Prof. Hui Jiang Process. Prof. Hui Jiang Dept of Electrical Engineering and Computer Science, York University
EECS3221.3 Operating System Fundamentals No.2 Process Prof. Hui Jiang Dept of Electrical Engineering and Computer Science, York University How OS manages CPU usage? How CPU is used? Users use CPU to run
More informationSystem Programming. Process Control III
Content : by Dr. B. Boufama School of Computer Science University of Windsor Instructor: Dr. A. Habed adlane@cs.uwindsor.ca http://cs.uwindsor.ca/ adlane/60-256 Content Content 1 Differentiating a process:
More informationProcess. Prepared by Prof. Hui Jiang Dept. of EECS, York Univ. 1. Process in Memory (I) PROCESS. Process. How OS manages CPU usage? No.
EECS3221.3 Operating System Fundamentals No.2 Prof. Hui Jiang Dept of Electrical Engineering and Computer Science, York University How OS manages CPU usage? How CPU is used? Users use CPU to run programs
More informationCS , Spring Sample Exam 3
Andrew login ID: Full Name: CS 15-123, Spring 2010 Sample Exam 3 Mon. April 6, 2009 Instructions: Make sure that your exam is not missing any sheets, then write your full name and Andrew login ID on the
More informationProcesses & Threads. Today. Next Time. ! Process concept! Process model! Implementing processes! Multiprocessing once again. ! More of the same J
Processes & Threads Today! Process concept! Process model! Implementing processes! Multiprocessing once again Next Time! More of the same J The process model! Most computers can do more than one thing
More informationSystem Programming. Process Control II
Content : by Dr. B. Boufama School of Computer Science University of Windsor Instructor: Dr. A. Habed adlane@cs.uwindsor.ca http://cs.uwindsor.ca/ adlane/60-256 Content Content 1 Terminating a process
More informationCS240: Programming in C
CS240: Programming in C Lecture 17: Processes, Pipes, and Signals Cristina Nita-Rotaru Lecture 17/ Fall 2013 1 Processes in UNIX UNIX identifies processes via a unique Process ID Each process also knows
More informationParents and Children
1 Process Identifiers Every process apart from the PID also has a PUID and a PGID. There are two types of PUID and PGID: real and effective. The real PUID is always equal to the user running the process
More informationFall 2015 COMP Operating Systems. Lab #3
Fall 2015 COMP 3511 Operating Systems Lab #3 Outline n Operating System Debugging, Generation and System Boot n Review Questions n Process Control n UNIX fork() and Examples on fork() n exec family: execute
More informationImportant Dates. October 27 th Homework 2 Due. October 29 th Midterm
CSE333 SECTION 5 Important Dates October 27 th Homework 2 Due October 29 th Midterm String API vs. Byte API Recall: Strings are character arrays terminated by \0 The String API (functions that start with
More informationWindows architecture. user. mode. Env. subsystems. Executive. Device drivers Kernel. kernel. mode HAL. Hardware. Process B. Process C.
Structure Unix architecture users Functions of the System tools (shell, editors, compilers, ) standard library System call Standard library (printf, fork, ) OS kernel: processes, memory management, file
More informationWeek 2 Intro to the Shell with Fork, Exec, Wait. Sarah Diesburg Operating Systems CS 3430
Week 2 Intro to the Shell with Fork, Exec, Wait Sarah Diesburg Operating Systems CS 3430 1 Why is the Shell Important? Shells provide us with a way to interact with the core system Executes programs on
More informationChap 4, 5: Process. Dongkun Shin, SKKU
Chap 4, 5: Process 1 Process Concept Job A bundle of program and data to be executed An entity before submission for execution Process (= running program) An entity that is registered to kernel for execution
More information518 Lecture Notes Week 3
518 Lecture Notes Week 3 (Sept. 15, 2014) 1/8 518 Lecture Notes Week 3 1 Topics Process management Process creation with fork() Overlaying an existing process with exec Notes on Lab 3 2 Process management
More informationOS Lab Tutorial 1. Spawning processes Shared memory
OS Lab Tutorial 1 Spawning processes Shared memory The Spawn exec() family fork() The exec() Functions: Out with the old, in with the new The exec() functions all replace the current program running within
More informationIntroduction to OS Processes in Unix, Linux, and Windows MOS 2.1 Mahmoud El-Gayyar
Introduction to OS Processes in Unix, Linux, and Windows MOS 2.1 Mahmoud El-Gayyar elgayyar@ci.suez.edu.eg Mahmoud El-Gayyar / Introduction to OS 1 Processes in Unix, Linux, and Windows Unix pre-empted
More informationProcesses. Today. Next Time. ! Process concept! Process model! Implementing processes! Multiprocessing once again. ! Scheduling processes
Processes Today! Process concept! Process model! Implementing processes! Multiprocessing once again Next Time! Scheduling processes The process model! Most computers can do more than one thing at a time
More informationChapter 3: Process Concept
Chapter 3: Process Concept Chapter 3: Process Concept Process Concept Process Scheduling Operations on Processes Inter-Process Communication (IPC) Communication in Client-Server Systems Objectives 3.2
More informationChapter 3: Process Concept
Chapter 3: Process Concept Chapter 3: Process Concept Process Concept Process Scheduling Operations on Processes Inter-Process Communication (IPC) Communication in Client-Server Systems Objectives 3.2
More informationLecture 23: System-Level I/O
CSCI-UA.0201-001/2 Computer Systems Organization Lecture 23: System-Level I/O Mohamed Zahran (aka Z) mzahran@cs.nyu.edu http://www.mzahran.com Some slides adapted (and slightly modified) from: Clark Barrett
More informationIntroduction to Processes
Computer Systems II Introduction to Processes 1 Review: Basic Computer Hardware CPU Instruction Register Control BUS read (disk) local buffer Disk Controller Memory Executable Disk 1 Review: Timing Problem
More informationChapter 3: Process Concept
Chapter 3: Process Concept Silberschatz, Galvin and Gagne 2013! Chapter 3: Process Concept Process Concept" Process Scheduling" Operations on Processes" Inter-Process Communication (IPC)" Communication
More informationCS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2018 Lecture 20
CS24: INTRODUCTION TO COMPUTING SYSTEMS Spring 2018 Lecture 20 LAST TIME: UNIX PROCESS MODEL Began covering the UNIX process model and API Information associated with each process: A PID (process ID) to
More informationCSC209F Midterm (L0101) Fall 1999 University of Toronto Department of Computer Science
CSC209F Midterm (L0101) Fall 1999 University of Toronto Department of Computer Science Date: October 26, 1999 Time: 1:10 pm Duration: 50 minutes Notes: 1. This is a closed book test, no aids are allowed.
More informationChapter 3: Processes
Chapter 3: Processes Silberschatz, Galvin and Gagne 2013 Chapter 3: Processes Process Concept Process Scheduling Operations on Processes Interprocess Communication Examples of IPC Systems Communication
More informationstructs as arguments
Structs A collection of related data items struct record { char name[maxname]; int count; ; /* The semicolon is important! It terminates the declaration. */ struct record rec1; /*allocates space for the
More informationUnix Processes. What is a Process?
Unix Processes Process -- program in execution shell spawns a process for each command and terminates it when the command completes Many processes all multiplexed to a single processor (or a small number
More informationCSC209H Lecture 6. Dan Zingaro. February 11, 2015
CSC209H Lecture 6 Dan Zingaro February 11, 2015 Zombie Children (Kerrisk 26.2) As with every other process, a child process terminates with an exit status This exit status is often of interest to the parent
More informationReading Assignment 4. n Chapter 4 Threads, due 2/7. 1/31/13 CSE325 - Processes 1
Reading Assignment 4 Chapter 4 Threads, due 2/7 1/31/13 CSE325 - Processes 1 What s Next? 1. Process Concept 2. Process Manager Responsibilities 3. Operations on Processes 4. Process Scheduling 5. Cooperating
More informationEXPERIMENT NO : M/C Lenovo Think center M700 Ci3,6100,6th Gen. H81, 4GB RAM,500GB HDD
GROUP - C EXPERIMENT NO : 12 1. Title: Implement UNIX system calls like ps, fork, join, exec family, and wait for process management (use shell script/ Java/ C programming) 2. Objectives : - To understand
More informationCS370 Operating Systems
CS370 Operating Systems Colorado State University Yashwant K Malaiya Fall 2017 Lecture a Slides based on Text by Silberschatz, Galvin, Gagne Various sources 1 1 FAQ? Notes: TA office hours on the web PA1
More informationKilling Zombies, Working, Sleeping, and Spawning Children
Killing Zombies, Working, Sleeping, and Spawning Children CS 333 Prof. Karavanic (c) 2015 Karen L. Karavanic 1 The Process Model The OS loads program code and starts each job. Then it cleans up afterwards,
More informationPROCESS CONTROL BLOCK TWO-STATE MODEL (CONT D)
MANAGEMENT OF APPLICATION EXECUTION PROCESS CONTROL BLOCK Resources (processor, I/O devices, etc.) are made available to multiple applications The processor in particular is switched among multiple applications
More informationProcesses. CS3026 Operating Systems Lecture 05
Processes CS3026 Operating Systems Lecture 05 Dispatcher Admit Ready Queue Dispatch Processor Release Timeout or Yield Event Occurs Blocked Queue Event Wait Implementation: Using one Ready and one Blocked
More informationMon Sep 17, 2007 Lecture 3: Process Management
Mon Sep 17, 2007 Lecture 3: Process Management September 19, 2007 1 Review OS mediates between hardware and user software QUIZ: Q: Name three layers of a computer system where the OS is one of these layers.
More informationHyo-bong Son Computer Systems Laboratory Sungkyunkwan University
File I/O Hyo-bong Son (proshb@csl.skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu Unix Files A Unix file is a sequence of m bytes: B 0, B 1,..., B k,..., B m-1 All I/O
More informationProcess. Heechul Yun. Disclaimer: some slides are adopted from the book authors slides with permission 1
Process Heechul Yun Disclaimer: some slides are adopted from the book authors slides with permission 1 Recap OS services Resource (CPU, memory) allocation, filesystem, communication, protection, security,
More informationProcess management 1
Process management 1 The kernel The core set of service that the OS provides 2 User Mode & kernel mode User mode apps delegate to system APIs in order to access hardware User space Kernel space User Utilities
More informationCSC209 Fall Karen Reid 1
' & ) ) #$ "! How user programs interact with the Operating System. Somehow we need to convert a program into machine code (object code). A compiler passes over a whole program before translating it into
More informationCSE 380 Computer Operating Systems. Instructor: Insup Lee. University of Pennsylvania Fall 2003
CSE 380 Computer Operating Systems Instructor: Insup Lee University of Pennsylvania Fall 2003 Lecture Note 2: Processes and Threads Lecture Note 2.1: Processes and System Calls 1 Process q Consider a simple
More informationOperating System Labs. Yuanbin Wu
Operating System Labs Yuanbin Wu CS@ECNU Operating System Labs Project 3 Oral test Handin your slides Time Project 4 Due: 6 Dec Code Experiment report Operating System Labs Overview of file system File
More informationI/O OPERATIONS. UNIX Programming 2014 Fall by Euiseong Seo
I/O OPERATIONS UNIX Programming 2014 Fall by Euiseong Seo Files Files that contain a stream of bytes are called regular files Regular files can be any of followings ASCII text Data Executable code Shell
More informationCS Operating Systems Lab 3: UNIX Processes
CS 346 - Operating Systems Lab 3: UNIX Processes Due: February 15 Purpose: In this lab you will become familiar with UNIX processes. In particular you will examine processes with the ps command and terminate
More informationSystem Programming. Introduction to Unix
Content : by Dr. B. Boufama School of Computer Science University of Windsor Instructor: Dr. A. Habed adlane@cs.uwindsor.ca http://cs.uwindsor.ca/ adlane/60-256 Content Content 1 Introduction 2 3 Introduction
More informationProcesses. q Process concept q Process model and implementation q Multiprocessing once again q Next Time: Scheduling
Processes q Process concept q Process model and implementation q Multiprocessing once again q Next Time: Scheduling The process model Computers can do more than one thing at a time Hard to keep track of
More informationProcess Management! Goals of this Lecture!
Process Management! 1 Goals of this Lecture! Help you learn about:" Creating new processes" Programmatically redirecting stdin, stdout, and stderr" (Appendix) communication between processes via pipes"
More informationThis document gives a general overview of the work done by an operating system and gives specific examples from UNIX.
This document gives a general overview of the work done by an operating system and gives specific examples from UNIX. 1 Manages Resources: I/O devices (disk, keyboard, mouse, terminal) Memory Manages Processes:
More informationUNIX Processes. by Armin R. Mikler. 1: Introduction
UNIX Processes by Armin R. Mikler Overview The UNIX Process What is a Process Representing a process States of a process Creating and managing processes fork() wait() getpid() exit() etc. Files in UNIX
More informationI/O OPERATIONS. UNIX Programming 2014 Fall by Euiseong Seo
I/O OPERATIONS UNIX Programming 2014 Fall by Euiseong Seo Files Files that contain a stream of bytes are called regular files Regular files can be any of followings ASCII text Data Executable code Shell
More informationOS lpr. www. nfsd gcc emacs ls 1/27/09. Process Management. CS 537 Lecture 3: Processes. Example OS in operation. Why Processes? Simplicity + Speed
Process Management CS 537 Lecture 3: Processes Michael Swift This lecture begins a series of topics on processes, threads, and synchronization Today: processes and process management what are the OS units
More informationFile I/O. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University
File I/O Jin-Soo Kim (jinsookim@skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu Unix Files A Unix file is a sequence of m bytes: B 0, B 1,..., B k,..., B m-1 All I/O devices
More informationProcesses. Dr. Yingwu Zhu
Processes Dr. Yingwu Zhu Process Growing Memory Stack expands automatically Data area (heap) can grow via a system call that requests more memory - malloc() in c/c++ Entering the kernel (mode) Hardware
More informationLecture 4: Process Management
Lecture 4: Process Management (Chapters 2-3) Process: execution context of running program. A process does not equal a program! Process is an instance of a program Many copies of same program can be running
More informationOS lpr. www. nfsd gcc emacs ls 9/18/11. Process Management. CS 537 Lecture 4: Processes. The Process. Why Processes? Simplicity + Speed
Process Management CS 537 Lecture 4: Processes Today: processes and process management what are the OS units of execution? how are they represented inside the OS? how is the CPU scheduled across processes?
More informationCSE 451: Operating Systems Winter Module 4 Processes. Mark Zbikowski Allen Center 476
CSE 451: Operating Systems Winter 2015 Module 4 Processes Mark Zbikowski mzbik@cs.washington.edu Allen Center 476 2013 Gribble, Lazowska, Levy, Zahorjan Process management This module begins a series of
More informationProcess Creation in UNIX
Process Creation in UNIX int fork() create a child process identical to parent Child process has a copy of the address space of the parent process On success: Both parent and child continue execution at
More informationThe course that gives CMU its Zip! I/O Nov 15, 2001
15-213 The course that gives CMU its Zip! I/O Nov 15, 2001 Topics Files Unix I/O Standard I/O A typical hardware system CPU chip register file ALU system bus memory bus bus interface I/O bridge main memory
More informationProcess management. What s in a process? What is a process? The OS s process namespace. A process s address space (idealized)
Process management CSE 451: Operating Systems Spring 2012 Module 4 Processes Ed Lazowska lazowska@cs.washington.edu Allen Center 570 This module begins a series of topics on processes, threads, and synchronization
More informationLecture 5. Systems Programming: Unix Processes Creation: fork & exec Process Communication: Pipes
Lecture 5 Systems Programming: Unix Processes Creation: fork & exec Process Communication: Pipes 1 Unix Process Creation Creation Management Destruction examples are in ~mark/pub/51081/ processes 2 Process
More informationFile I/O. Dong-kun Shin Embedded Software Laboratory Sungkyunkwan University Embedded Software Lab.
1 File I/O Dong-kun Shin Embedded Software Laboratory Sungkyunkwan University http://nyx.skku.ac.kr Unix files 2 A Unix file is a sequence of m bytes: B 0, B 1,..., B k,..., B m-1 All I/O devices are represented
More informationCSE 153 Design of Operating Systems Fall 2018
CSE 153 Design of Operating Systems Fall 2018 Lecture 4: Processes (2) Threads Process Creation: Unix In Unix, processes are created using fork() int fork() fork() Creates and initializes a new PCB Creates
More informationPrinceton University Computer Science 217: Introduction to Programming Systems. Process Management
Princeton University Computer Science 217: Introduction to Programming Systems Process Management 1 Goals of this Lecture Help you learn about: Creating new processes Waiting for processes to terminate
More informationToday: Process Management. The Big Picture So Far. What's in a Process? Example Process State in Memory
The Big Picture So Far Today: Process Management From the Architecture to the OS to the User: Architectural resources, OS management, and User Abstractions. A process as the unit of execution. Hardware
More informationThe Big Picture So Far. Today: Process Management
The Big Picture So Far From the Architecture to the OS to the User: Architectural resources, OS management, and User Abstractions. Hardware abstraction Processor Memory I/O devices File System Distributed
More informationCSE 410: Computer Systems Spring Processes. John Zahorjan Allen Center 534
CSE 410: Computer Systems Spring 2018 Processes John Zahorjan zahorjan@cs.washington.edu Allen Center 534 1. What is a process? Processes 2. What's the process namespace? 3. How are processes represented
More informationCS 201. Files and I/O. Gerson Robboy Portland State University
CS 201 Files and I/O Gerson Robboy Portland State University A Typical Hardware System CPU chip register file ALU system bus memory bus bus interface I/O bridge main memory USB controller graphics adapter
More informationLinux System Administration
System Processes Objective At the conclusion of this module, the student will be able to: Describe and define a process Identify a process ID, the parent process and the child process Learn the PID for
More informationProcess Management 1
Process Management 1 Goals of this Lecture Help you learn about: Creating new processes Programmatically redirecting stdin, stdout, and stderr (Appendix) communication between processes via pipes Why?
More informationOperating System Design
Operating System Design Processes Operations Inter Process Communication (IPC) Neda Nasiriani Fall 2018 1 Process 2 Process Lifecycle 3 What information is needed? If you want to design a scheduler to
More informationOperating Systems CMPSCI 377 Spring Mark Corner University of Massachusetts Amherst
Operating Systems CMPSCI 377 Spring 2017 Mark Corner University of Massachusetts Amherst Clicker Question #1 Program == Process (A) True (B) False Answer on Next Slide The Big Picture So Far Hardware abstraction
More informationProcesses. Operating System CS 217. Supports virtual machines. Provides services: User Process. User Process. OS Kernel. Hardware
es CS 217 Operating System Supports virtual machines Promises each process the illusion of having whole machine to itself Provides services: Protection Scheduling Memory management File systems Synchronization
More informationChapter 3: Processes. Operating System Concepts Essentials 2 nd Edition
Chapter 3: Processes Silberschatz, Galvin and Gagne 2013 Chapter 3: Processes Process Concept Process Scheduling Operations on Processes Interprocess Communication Examples of IPC Systems Communication
More informationwww nfsd emacs lpr Process Management CS 537 Lecture 4: Processes Example OS in operation Why Processes? Simplicity + Speed
Process Management CS 537 Lecture 4: Processes Michael Swift This lecture begins a series of topics on processes, threads, and synchronization Today: processes and process management what are the OS units
More informationSystem- Level I/O. Andrew Case. Slides adapted from Jinyang Li, Randy Bryant and Dave O Hallaron
System- Level I/O Andrew Case Slides adapted from Jinyang Li, Randy Bryant and Dave O Hallaron 1 Unix I/O and Files UNIX abstracts many things into files (just a series of bytes) All I/O devices are represented
More informationProcesses. Today. Next Time. Process concept Process model Implementing processes Multiprocessing once again. Scheduling processes
Processes Today Process concept Process model Implementing processes Multiprocessing once again Next Time Scheduling processes The process model Most computers can do more than one thing at a time Hard
More informationfork System-Level Function
Princeton University Computer Science 217: Introduction to Programming Systems Process Management Goals of this Lecture Help you learn about: Creating new processes Waiting for processes to terminate Executing
More informationPrinceton University Computer Science 217: Introduction to Programming Systems. Process Management
Princeton University Computer Science 217: Introduction to Programming Systems Process Management 1 Goals of this Lecture Help you learn about: Creating new processes Waiting for processes to terminate
More informationPreview. Process Control. What is process? Process identifier The fork() System Call File Sharing Race Condition. COSC350 System Software, Fall
Preview Process Control What is process? Process identifier The fork() System Call File Sharing Race Condition COSC350 System Software, Fall 2015 1 Von Neumann Computer Architecture: An integrated set
More informationComputer Systems Assignment 2: Fork and Threads Package
Autumn Term 2018 Distributed Computing Computer Systems Assignment 2: Fork and Threads Package Assigned on: October 5, 2018 Due by: October 12, 2018 1 Understanding fork() and exec() Creating new processes
More informationWhat Is A Process? Process States. Process Concept. Process Control Block (PCB) Process State Transition Diagram 9/6/2013. Process Fundamentals
What Is A Process? A process is a program in execution. Process Fundamentals #include int main(int argc, char*argv[]) { int v; printf( hello world\n ); scanf( %d, &v); return 0; Program test
More informationPrinceton University. Computer Science 217: Introduction to Programming Systems. Process Management
Princeton University Computer Science 217: Introduction to Programming Systems Process Management 1 Goals of this Lecture Help you learn about: Creating new processes Waiting for processes to terminate
More informationProcesses & Threads. (Chapter 3) CS 4410 Operating Systems. [R. Agarwal, L. Alvisi, A. Bracy, M. George, E. Sirer, R. Van Renesse]
Processes & Threads (Chapter 3) CS 4410 Operating Systems [R. Agarwal, L. Alvisi, A. Bracy, M. George, E. Sirer, R. Van Renesse] Processes! 2 What is a Program? Program is a file containing: executable
More informationProcess Management! Goals of this Lecture!
Process Management! 1 Goals of this Lecture! Help you learn about:" Creating new processes" Programmatically redirecting stdin, stdout, and stderr" Unix system-level functions for I/O" The Unix stream
More information