Presentation is loading. Please wait.

Presentation is loading. Please wait.

2.1 Processes process = abstraction of a running program

Similar presentations


Presentation on theme: "2.1 Processes process = abstraction of a running program"— Presentation transcript:

1 2.1 Processes process = abstraction of a running program
multiprogramming = CPU switches from running program to running program pseudoparallelism each process has its own virtual CPU each process is considered to be simply sequential make no assumptions about timing

2 Processes cont’d critcal real-time requirements = particular events must occur within a specified number of milliseconds difference between a process and a program

3 Process creation 4 major events causing process creation:
system initialization running process executes a process creation system call user requests creation of a new process initiation of a batch job daemon = background process to handle some activities (e. g., , telnet, ftp, web server, etc.)

4 Process creation cont’d
win32: use task manager to view process Unix: ps –edalf command

5 Process creation cont’d
win32: CreateProcess() 10 parameters creates and loads new process Unix: fork() + execve() system calls fork() creates new process (copy of parent) execve() loads new program

6 Unix process creation: fork()
#include <stdio.h> #include <sys/types.h> #include <unistd.h> int main ( const int argc, const char* const argv[] ) { puts( "forking" ); pid_t ret = fork(); puts( "forked" ); return 0; }

7 fork and exec #include <stdio.h> #include <sys/types.h>
#include <unistd.h> int main ( const int argc, const char* const argv[] ) { puts( "parent: forking" ); pid_t ret = fork(); switch (ret) { case -1: puts( "parent: error: fork failed!" ); break; case 0: puts( "child: here (before execl)!" ); if (execl( "./child.exe", "./child.exe", 0 )==-1) perror( "child: execl failed:" ); puts( "child: here (after execl)!" ); //should never get here default: printf( "parent: child has pid=%d \n", ret ); } return 0; fork and exec

8 Child process #include <stdio.h>
int main ( const int argc, const char* const argv[] ) { printf( "child process %s running with %d arg(s). \n", argv[0], argc ); return 0; }

9 Process termination Conditions: Voluntary: Involuntary: Normal exit
Error exit Win32: ExitProcess() Unix: exit() Involuntary: Fatal error (e. g., divide by zero, illegal memory access) Killed by another process

10 Process hierarchies None in win32
Unix maintains a parent/child relationship called a process group.

11 Process states Running Ready Blocked

12 Implementation of processes
Process table = array of structures (process control blocks)

13 Context switch/interrupt service


Download ppt "2.1 Processes process = abstraction of a running program"

Similar presentations


Ads by Google