CS2106 Tutorial 2

1,197 views
1,137 views

Published on

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,197
On SlideShare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
1
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

CS2106 Tutorial 2

  1. 1. National University of Singapore School of Computing CS2106 Tutorial 2 Semester 1 10/11 1. Adapted from SGG Problem 3.9 Including the initial parent process, how many processes are created by the following pro- gram? int main() { for (int i = 0; i < 3; i++) fork(); } 2. Adapted from SGG Problem 3.13 Explain the output of Line A in the following program. int value = 5; int main() { pid_t pid; pid = fork(); if (pid == 0) { value += 15; } else if (pid > 0) { wait(NULL); printf("PARENT: value = %dn", value); /* LINE A */ } return 0; } 3. A common code sequence is to call fork() to create a child process with a copy of the parent process’s core image, followed by execve() to replace the child’s core image with the core image of another executable. You might have noticed the inefficiency here: we spend the effort to duplicate the core image of the parent process to the child process in fork(), only to have the core image overwritten by execve(). Suggest two ways where we can avoid this wasted effort. 4. What are the advantages of implementing the Web browser using multiple processes (one process per tab) versus multiple threads (one thread per tab)?

×