2.1 processes process = abstraction of a running program multiprogramming = cpu switches from…
Post on 19-Jan-2018
212 Views
Preview:
DESCRIPTION
TRANSCRIPT
2.1 Processes2.1 Processes process = abstraction of a running process = abstraction of a running
programprogram multiprogramming = CPU switches from multiprogramming = CPU switches from
running program to running programrunning program to running program pseudoparallelismpseudoparallelism each process has its own virtual CPUeach process has its own virtual CPU
each process is considered to be simply each process is considered to be simply sequentialsequential
make no assumptions about timingmake no assumptions about timing
Processes cont’dProcesses cont’d
critcal real-time requirements = particular critcal real-time requirements = particular events must occur within a specified events must occur within a specified number of millisecondsnumber of milliseconds
difference between a process and a difference between a process and a programprogram Process – an activityProcess – an activity
= program, input, output, and state= program, input, output, and state
Process TypesProcess Types
1.1. Foreground – process that interacts with Foreground – process that interacts with useruser
2.2. Background – not associated with a Background – not associated with a specific user; specific/dedicated functionspecific user; specific/dedicated function
daemon = background process to handle daemon = background process to handle some activities (e. g., email, telnet, ftp, web some activities (e. g., email, telnet, ftp, web server, etc.)server, etc.)
Process creationProcess creation
4 major events causing process 4 major events causing process creation:creation:
1.1. system initializationsystem initialization2.2. running process executes a process running process executes a process
creation system callcreation system call3.3. user requests creation of a new user requests creation of a new
processprocess4.4. initiation of a batch jobinitiation of a batch job
Process creation cont’dProcess creation cont’d
win32: use task manager to view processwin32: use task manager to view process
Unix: ps –edalf commandUnix: ps –edalf command
Process creation cont’dProcess creation cont’d
win32: CreateProcess()win32: CreateProcess() 10 parameters10 parameters creates and loads new processcreates and loads new process
Unix: fork() + execve() system callsUnix: fork() + execve() system calls fork() creates new process (copy of parent)fork() creates new process (copy of parent) execve() loads new programexecve() loads new program
Unix process creation: fork()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;}
#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 herebreak;
default: printf( "parent: child has pid=%d \n", ret );break;
} return 0;}
fork and execfork and exec
Child processChild 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;}
Process terminationProcess termination Conditions:Conditions:
Voluntary:Voluntary: Normal exitNormal exit Error exitError exit Win32: ExitProcess()Win32: ExitProcess() Unix: exit()Unix: exit()
Involuntary:Involuntary: Fatal error (e. g., divide by zero, illegal memory Fatal error (e. g., divide by zero, illegal memory
access)access) Killed by another processKilled by another process
Process hierarchiesProcess hierarchies
None in win32None in win32 Unix maintains a parent/child relationship Unix maintains a parent/child relationship
called a process group.called a process group.
Process statesProcess states
1.1. RunningRunning2.2. ReadyReady3.3. BlockedBlocked
Implementation of processesImplementation of processes
Process table = array of structures Process table = array of structures (process control blocks)(process control blocks)
Context switch/interrupt serviceContext switch/interrupt service
top related