Unix Network Programming Assignment-3

Winter Semester,Department of Computer Science

University of Hyderabad

Max.Marks : 10 Deadline : 20-02-05.

Note : Answer All Questions , Precise Answers will be appreciated.

1. Implement the following scenario using pipes/named-pipes and signals.
	There are two processes p1 and p2  and  c1 is the child of the process p1.

If c1 sends a user signal (ex: SIGUSR1) to p1 then p1 sends another user signal (ex:SIGUSR2) to p2 , after getting the signal from p1 , p2 sends its current priority to process p1 through a named pipe. After receiving the priority of p2 , p1 sends a message "Hi Neha" to c1 through a pipe and c1 returns a message "Hello Soujanya" to p1 through another pipe. Note : Use /proc file system for getting the current priority. Hint: U can also use getpriority() system call. 2. Two computer science students, Vijay and Praveen, are having discussion about the following program. Vijay says that this program outputs zeros, ones, zeros, ones, and so on, alternating forever. Praveen disagrees. Who is correct? Why ? Explain. Hint : Guess the output of the program without executing it.

#include <signal.h> #include <stdio.h> struct two_int { int a, b; } data; void signal_handler(int signum){ printf ("%d, %d\n", data.a, data.b); alarm (1); } int main (void){ static struct two_int zeros = { 0, 0 }, ones = { 1, 1 }; signal (SIGALRM, signal_handler); data = zeros; alarm (1); while (1) {data = zeros; data = ones;} return 0; }

3. Is there any need of hardware support for signal handling? Discuss.