1 / 21

2.1 Processes

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.

Download Presentation

2.1 Processes

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 2.1 Processes • process = abstraction of a running program

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

  3. 2.1 Processes Make no assumptions about timing! • Ex. • Start process A. • Start process B. • Which ends first? • Ex. • Start running test.exe. • Start running a second test.exe. • Which ends first? Make no assumptions about timing unless . . .

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

  5. Processes cont’d • What’s the difference between a process and a program? • process – an activity • = program + input + output + state

  6. Process Types • Foreground – process that interacts with user • Background – not associated with a specific user; specific/dedicated function • daemon = background process to handle some activities (e. g., email, telnet, ftp, web server, etc.)

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

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

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

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

  11. #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 break; default: printf( "parent: child has pid=%d \n", ret ); break; } return 0; } fork and exec

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

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

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

  15. Process states • Running • Ready • Blocked

  16. Implementation of processes • Process table = array of structures (process control blocks)

  17. Implementation of processes structProcessManagement { inteax, ebx, ecx, …; int pc; inteflags; … };

  18. Implementation of processes structMemoryManagement { char* text; char* data; char* stack; };

  19. Implementation of processes #define MAX_FDS 100 //max open files structFileManagement { char* root; char* working; intfd[ MAX_FDS ]; intuserID; intgroupID; };

  20. Implementation of processes Process table = array of structures (process control blocks) structProcessTable { structProcessManagement pm; structMemoryManagement mm; structFileManagement fm; }; #define MAX_PROCESSES 500 structProcessTable pt[ MAX_PROCESSES ];

  21. Context switch/interrupt service

More Related