{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

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

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

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

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

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

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

View Full Document Right Arrow Icon
Programmer’s Model of Multitasking, cont. box2 execl() and execve() run a new program in an existing process square6 Called once, (normally) never returns square6 Programming Challenge box2 Understanding the nonstandard semantics of the functions box2 Avoiding improper use of system resources square6 E.g. “Fork bombs” can disable a system.
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; if (waitpid(pid, &status, 0) < 0) unix_error("waitfg: waitpid error"); } else /* otherwise, don’t wait for bg job */ printf("%d %s", pid, cmdline); } }
Image of page 5

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

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

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

View Full Document Right Arrow Icon
Signals, cont. box2 Kernel abstraction for exceptions and interrupts. box2 Sent from the kernel (sometimes at the request of another process) to a process. box2 Different signals are identified by small integer ID’s box2 The only information in a signal is its ID and the fact that it arrived.
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
Image of page 9

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

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

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern