

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Material Type: Exam; Professor: Hsu; Class: UNIX System Programming; Subject: Computer Programming; University: Florida Atlantic University; Term: Spring 2007;
Typology: Exams
1 / 3
This page cannot be seen from the preview
Don't miss anything!


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.
2
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 }