CSC320 chapter8 - The World of Multitasking System Runs...

Info iconThis preview shows pages 1–11. Sign up to view the full content.

View Full Document Right Arrow Icon
The World of Multitasking s System Runs Many Processes Concurrently b Process: executing program s State consists of memory image + register values + program counter b Continually switches from one process to another s Suspend process when it needs I/O resource or timer event occurs s Resume process when I/O available or given scheduling priority
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
The World of Multitasking, cont. b Appears to user(s) as if all processes executing simultaneously s Even though most systems can only execute one process at a time s Except possibly with lower performance than if running alone
Background image of page 2
Programmer’s Model of Multitasking s Basic Functions b fork() spawns new process s Called once, returns twice b exit() terminates own process s Called once, never returns s Puts it into “zombie” status b wait() and waitpid() wait for and reap terminated children
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Programmer’s Model of Multitasking, cont. b execl() and execve() run a new program in an existing process s Called once, (normally) never returns s Programming Challenge b Understanding the nonstandard semantics of the functions b Avoiding improper use of system resources s E.g. “Fork bombs” can disable a system.
Background image of page 4
Simple Shell eval Function void eval(char *cmdline) { char *argv[MAXARGS]; /* argv for execve() */ int bg; /* should the job run in bg or fg? */ pid_t pid; /* process id */ bg = parseline(cmdline, argv); if (!builtin_command(argv)) { if ((pid = Fork()) == 0) { /* child runs user job */ if (execve(argv[0], argv, environ) < 0) { printf("%s: Command not found.\n", argv[0]); exit(0); } } if (!bg) { /* parent waits for fg job to terminate */ int status; unix_error("waitfg: waitpid error"); } else /* otherwise, don’t wait for bg job */ printf("%d %s", pid, cmdline); } }
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Problem with Simple Shell Example s Shell correctly waits for and reaps foreground jobs. s But what about background jobs? b Will become zombies when they terminate. b Will never be reaped because shell (typically) will not terminate. b Creates a memory leak that will eventually crash the kernel when it runs out of memory.
Background image of page 6
Signals s Solution: Reaping background jobs requires a mechanism called a signal . s A signal is a small message that notifies a process that an event of some type has occurred in the system.
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Signals, cont. b Kernel abstraction for exceptions and interrupts. b Sent from the kernel (sometimes at the request of another process) to a process. b Different signals are identified by small integer ID’s b The only information in a signal is its ID and the fact that it arrived.
Background image of page 8
Signals, cont. Timer signal Terminate SIGALRM 14 Segmentation violation Terminate & Dump SIGSEGV 11 17 9 2 ID Child stopped or terminated Ignore SIGCHLD Kill program (cannot override or ignore) Terminate SIGKILL Interrupt from keyboard ( ctl-c ) Terminate SIGINT Corresponding Event Default Action Name
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Signals, cont. s
Background image of page 10
Image of page 11
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 11/28/2011 for the course COMPUTER S 320 taught by Professor Dr.safwanqasem during the Spring '11 term at King Saud University.

Page1 / 40

CSC320 chapter8 - The World of Multitasking System Runs...

This preview shows document pages 1 - 11. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online