Midterm Exam - Unix System Programming - Spring 2007 | COP 4604, Exams of Computer Science

Material Type: Exam; Professor: Hsu; Class: UNIX System Programming; Subject: Computer Programming; University: Florida Atlantic University; Term: Spring 2007;

Typology: Exams

Pre 2010

Uploaded on 07/28/2009

koofers-user-b6x
koofers-user-b6x 🇺🇸

10 documents

1 / 3

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
COP 4604001 – Spring 2007 Name _______________________________
Midterm 2 Last 5 digits of SSN: xxx-x __-__ __ __ __
This is an OPEN textbook, but CLOSED notes test. You may consult your textbook for syntax
questions. No other reference materials are allowed to be open. You must write you name and SS# on
each sheet detached.
1. What is the difference between exit() and _exit(). Can you think of any application that _exit()
instead of exit() is needed? (20 pts.)
2. Briefly explain the difference between execle() and execvp(). (15 pts.)
3. What is a zombie process? Can zombie processes be avoided? Explain. (20 pts.)
pf3

Partial preview of the text

Download Midterm Exam - Unix System Programming - Spring 2007 | COP 4604 and more Exams Computer Science in PDF only on Docsity!

COP 4604001 – Spring 2007 Name _______________________________

Midterm 2 Last 5 digits of SSN: xxx-x - __ __ __

This is an OPEN textbook, but CLOSED notes test. You may consult your textbook for syntax questions. No other reference materials are allowed to be open. You must write you name and SS# on each sheet detached.

  1. What is the difference between exit () and _exit (). Can you think of any application that _exit () instead of exit () is needed? (20 pts.)
  2. Briefly explain the difference between execle () and execvp (). (15 pts.)
  3. What is a zombie process? Can zombie processes be avoided? Explain. (20 pts.)

2

  1. Briefly explain what the following program does in terms of the functions of the parent and child processes. Show possible execution results. Identify what you consider any bug(s) in it. (20 pts.)

1 #include <stdio.h> 2 #define MESG "This is a message\n" 3 char *mesg_c, *mesg_p;

4 char *alloc_buf(size_t size) 5 { 6 return((char *)malloc(size)); 7 }

8 main() 9 { 10 int pid, size;

11 size = strlen(MESG); 12 if ((pid = fork()) > 0) { 13 waitpid(pid, (int *)NULL, 0); 14 mesg_p = alloc_buf((size_t)size+1); 15 strcpy(mesg_p, mesg_c); 16 printf("mesg_p = %s", mesg_p); 17 exit(0); 18 } 19 mesg_c = alloc_buf((size_t)size+1); 20 strcpy(mesg_c, MESG); 21 printf("mesg_c = %s", mesg_c); 22 exit(0); 23 }