2.1 processes

21
2.1 Processes 2.1 Processes process = abstraction of a process = abstraction of a running program running program

Upload: kendall-savage

Post on 31-Dec-2015

19 views

Category:

Documents


1 download

DESCRIPTION

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. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: 2.1 Processes

2.1 Processes2.1 Processes

process = abstraction of a running process = abstraction of a running programprogram

Page 2: 2.1 Processes

2.1 Processes2.1 Processes

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

Page 3: 2.1 Processes

2.1 Processes2.1 Processes

Make no assumptions about timing!Make no assumptions about timing! Ex.Ex.

1.1. Start process A.Start process A.2.2. Start process B.Start process B.3.3. Which ends first?Which ends first?

Ex.Ex.1.1. Start running test.exe.Start running test.exe.2.2. Start running a second test.exe.Start running a second test.exe.3.3. Which ends first?Which ends first?

Make no assumptions about timing unless . . .Make no assumptions about timing unless . . .

Page 4: 2.1 Processes

Processes cont’dProcesses cont’d

critical real-time requirements = particular critical real-time requirements = particular events must occur within a specified events must occur within a specified number of millisecondsnumber of milliseconds

Ex. QNX, VxWorks, RT11 (ancient), Ex. QNX, VxWorks, RT11 (ancient), Windows Embedded (see Windows Embedded (see http://www.microsoft.com/windowsembedded/en-us/about/solutions/medical-devices-healthcare.mspx?WT.mc_id=HS_search))

http://en.wikipedia.org/wiki/Real-time_operating_system

Page 5: 2.1 Processes

Processes cont’dProcesses cont’d

What’s the difference between a process What’s the difference between a process and a program?and a program?

process – an activityprocess – an activity

= program= program + input + output + state + input + output + state

Page 6: 2.1 Processes

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.)

Page 7: 2.1 Processes

Process creationProcess creation

4 major events causing process 4 major events causing process creation:creation:

1.1. system initializationsystem initialization

2.2. running process executes a process running process executes a process creation system callcreation system call

3.3. user requests creation of a new user requests creation of a new processprocess

4.4. initiation of a batch jobinitiation of a batch job

Page 8: 2.1 Processes

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

Page 9: 2.1 Processes

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

Page 10: 2.1 Processes

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;}

Page 11: 2.1 Processes

#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

Page 12: 2.1 Processes

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;}

Page 13: 2.1 Processes

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

Page 14: 2.1 Processes

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.

Page 15: 2.1 Processes

Process statesProcess states

1.1. RunningRunning

2.2. ReadyReady

3.3. BlockedBlocked

Page 16: 2.1 Processes

Implementation of processesImplementation of processes

Process table = array of structures Process table = array of structures (process control blocks)(process control blocks)

Page 17: 2.1 Processes

Implementation of processesImplementation of processes

struct ProcessManagement {struct ProcessManagement {

intint eax, ebx, ecx, …;eax, ebx, ecx, …;

intint pc;pc;

intint eflags;eflags;

……

};};

Page 18: 2.1 Processes

Implementation of processesImplementation of processes

struct MemoryManagement {struct MemoryManagement {

char*char* text;text;

char*char* data;data;

char*char* stack;stack;

};};

Page 19: 2.1 Processes

Implementation of processesImplementation of processes

#define MAX_FDS 100 //max open files#define MAX_FDS 100 //max open files

struct FileManagement {struct FileManagement {

char*char* root;root;

char*char* working;working;

intint fd[ MAX_FDS ];fd[ MAX_FDS ];

intint userID;userID;

intint groupID;groupID;

};};

Page 20: 2.1 Processes

Process table = array of structures (process control blocks)Process table = array of structures (process control blocks)

struct ProcessTable {struct ProcessTable {

struct ProcessManagementstruct ProcessManagement pm;pm;

struct MemoryManagementstruct MemoryManagement mm;mm;

struct FileManagementstruct FileManagement fm;fm;

};};

#define MAX_PROCESSES 500#define MAX_PROCESSES 500

struct ProcessTable pt[ MAX_PROCESSES ];struct ProcessTable pt[ MAX_PROCESSES ];

Implementation of processesImplementation of processes

Page 21: 2.1 Processes

Context switch/interrupt serviceContext switch/interrupt service