2.1 Processes process = abstraction of a running program
2.1 Processes 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
2.1 Processes Make no assumptions about timing! Ex. 1. Start process A. 2. Start process B. 3. Which ends first? Ex. 1. Start running test.exe. 2. Start running a second test.exe. 3. Which ends first? Make no assumptions about timing unless...
Processes cont’d critical real-time requirements = particular events must occur within a specified number of milliseconds Ex. QNX, VxWorks, RT11 (ancient), Windows Embedded (see ed/en-us/about/solutions/medical-devices- healthcare.mspx?WT.mc_id=HS_search) ed/en-us/about/solutions/medical-devices- healthcare.mspx?WT.mc_id=HS_search ed/en-us/about/solutions/medical-devices- healthcare.mspx?WT.mc_id=HS_search time_operating_system time_operating_system time_operating_system
Processes cont’d What’s the difference between a process and a program? process – an activity = program + input + output + state
Process Types 1. Foreground – process that interacts with user 2. Background – not associated with a specific user; specific/dedicated function daemon = background process to handle some activities (e. g., , telnet, ftp, web server, etc.)
Process creation 4 major events causing process creation: 1.system initialization 2.running process executes a process creation system call 3.user requests creation of a new process 4.initiation of a batch job
Process creation cont’d win32: use task manager to view process Unix: ps –edalf command
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
Unix process creation: fork() #include int main ( const int argc, const char* const argv[] ) { puts( "forking" ); pid_t ret = fork(); puts( "forked" ); return 0; }
#include 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 break; default:printf( "parent: child has pid=%d \n", ret ); break; } return 0; } fork and exec fork and exec
Child process #include 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 termination Conditions: Voluntary: Normal exit Error exit Win32: ExitProcess() Unix: exit() Involuntary: Fatal error (e. g., divide by zero, illegal memory access) Killed by another process
Process hierarchies None in win32 Unix maintains a parent/child relationship called a process group.
Process states 1. Running 2. Ready 3. Blocked
Implementation of processes Process table = array of structures (process control blocks)
Implementation of processes struct ProcessManagement { inteax, ebx, ecx, …; intpc; inteflags; …};
Implementation of processes struct MemoryManagement { char*text; char*data; char*stack; };
Implementation of processes #define MAX_FDS 100 //max open files struct FileManagement { char*root; char*working; intfd[ MAX_FDS ]; intuserID; intgroupID; };
Process table = array of structures (process control blocks) struct ProcessTable { struct ProcessManagementpm; struct MemoryManagementmm; struct FileManagementfm; }; #define MAX_PROCESSES 500 struct ProcessTable pt[ MAX_PROCESSES ]; Implementation of processes
Context switch/interrupt service