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

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

Typology: Exams

Pre 2010

Uploaded on 07/23/2009

koofers-user-20q
koofers-user-20q 🇺🇸

5

(1)

9 documents

1 / 3

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
1
COP 4604-001: Unix System Programming
Spring 2008 Name: ______________________________
Midterm 2 Last 4 digits of ZN: Z x x x 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. NO exchange of information is
allowed among students. Write your answers on the space provided.
1. Zombie processes are wastes of resources. List all possible ways, as covered in class, that a
zombie process can be avoided. (15 pts.)
1. Have parent wait
2. Have it orphaned
3. Have it (SIGCLD) ignored (SV)
4. Call sigaction() with SA_NOCLDWAIT set
2. What are the data types of the C variables in the following C declarations? (20 pts.)
a) int (*fa)(int);
fa is a pointer to an integer function that takes one integer parameter.
b) int (*fb(int, int (*fbb)(void)))(int, int);
fb is a function that takes two arguments (int & function) and returns a pointer to
an integer function with two integer arguments.
fbb is a pointer to an integer function that takes no argument.
c) int *fc(int i, int j);
fc is a function with two integer arguments, and returns an integer.
3. Explain what the following system calls are used for? (20 pts.)
a) signal()
To set up a signal handler
b) kill()
To send a signal
c) alarm()
To setup an alarm clock
d) pause()
To suspend the execution of a process
e) waitpid()
To wait for a specific child (pid) to finish
pf3

Partial preview of the text

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

COP 4604-001: Unix System Programming

Spring 2008 Name: ______________________________

Midterm 2 Last 4 digits of ZN : Z x x x 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. NO exchange of information is allowed among students. Write your answers on the space provided.

  1. Zombie processes are wastes of resources. List all possible ways, as covered in class, that a zombie process can be avoided. (15 pts.)
    1. Have parent wait
    2. Have it orphaned
    3. Have it (SIGCLD) ignored (SV)
    4. Call sigaction() with SA_NOCLDWAIT set
  2. What are the data types of the C variables in the following C declarations? (20 pts.)

a) int (* fa )(int);

fa is a pointer to an integer function that takes one integer parameter.

b) int (* fb (int, int (* fbb )(void)))(int, int);

fb is a function that takes two arguments (int & function) and returns a pointer to an integer function with two integer arguments.

fbb is a pointer to an integer function that takes no argument.

c) int * fc (int i, int j);

fc is a function with two integer arguments, and returns an integer.

  1. Explain what the following system calls are used for? (20 pts.)

a) signal() To set up a signal handler

b) kill() To send a signal

c) alarm() To setup an alarm clock

d) pause() To suspend the execution of a process

e) waitpid() To wait for a specific child (pid) to finish

  1. Show results of the following program. (20 pts.)

1 #include <stdio.h> 2 #include <sys/types.h> 3 int global = 10; 4 main(void) 5 { 6 void func1(void), func2(void); 7 func1(); 8 func2(); 9 } 10 void func1(void) 11 { 12 int i_local = 20; 13 static int s_local = 30; 14 if (fork()) { /* assume fork() is executed successfully */ 15 wait((char *)0); 16 printf("i_local = %d\n", i_local); 17 printf("s_local = %d\n", s_local); 18 return; 19 } 20 else { 21 global++; 22 i_local++; 23 s_local++; 24 } 25 } 26 void func2(void) 27 { 28 printf("global = %d\n", global); 29 }

child parent

global = 11 i_local = 20 s_local = 30 global = 10