CSC 414 Problems Session I, Spring 2007

Notre Dame University–Louaize · Applied Operating Systems · 1 page · Dr. Khaldoun El-Khaldi

All CSC 414 files
CSC 414 Problems Session I, Spring 2007, page 1

Stuck on a question? A tutor can walk you through it.

More CSC 414 files

Show the text of this problems
Exercise Session I - Processes 1. During a context switch, the operating system executes instructions that choose the next process to execute. These instructions are typically at a fixed location in memory. Why? We need to keep the context switch time as short as possible, so keeping the part of the OS that deals with context switches always in a fixed location in memory (rather than bring it in from disk every time or even on occasion), means the OS instructions will execute faster and the context switch time will be predictable. 2. Write a C/C++ program in which a parent forks a child, and the child forks a grandchild. The grandchild writes: "My process id is X, my parent's id is Y, and my Grandparent's id is Z" (where X, Y, and Z are the Unix process ids). #include #include #include main() { int parentId = getpid(); /* Id of this process, the grandparent */ int childId = fork(); if(childId == 0) { /* I'm the child of parentId */ childId = getpid() /* Find out my own Id */ int grchildId = fork(); if (grchildId == 0) { /* I'm the child of parentid */ grchildId = getpid(); /* find out my own Id */ cout << "My process id is" << grchildId << ",\n" ; cout << "My parent's id is" << childId << ",\n"; cout << "My Grandparent's id is" << parentId << ",\n"; } }