homework-1 - CSE 421/521 – Operating Systems Fall 2011 -...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: CSE 421/521 – Operating Systems Fall 2011 - Homework Assignment #1 The due date is: September 15th, Thursday, before the class (9:30am). Late submission is not allowed. int main(int argc, char *argv) P{ roblem 1: if (argc != 2) exit(0); pid_t pid; int i, a, b, fib; int n = atoi(argv[1]); Problem 2: / fork switches used for and What are *context another process */ what does a typical context switch involve? pid = fork(); Compare processes versus threads in terms of context switch operation and overhead associated { /* it. if (pid < 0) with error occurred */ Problem 3: fprintf(stderr, "Fork Failed\n"); exit(-1); } else if (pid == 0) { /* child process */ if (n == 1) printf("0\n"); else if (n == 2) printf("0, 1\n"); else if (n > 2) { a = 0; b = 1; printf("0, 1,"); for (i = 3; i < n; i++) { fib = a + b; printf("%d,",fib); a = b; b = fib; } Problem 4: printf("%d\n",a+b); Discuss the tradeoffs } between user and kernel threads. } (a)lsehat are the advantages and*/ e W { /* parent process disadvantages of each? /* parent will wait for the child to complete */ wait(NULL); (b) Assume we can make system calls as fast as procedure calls using some new hardware mechanism. Would this make one kind of thread exit(0); clearly preferable over the other? Explain briefly. } } Problem 5: ...
View Full Document

Ask a homework question - tutors are online