Menu

Class 11: Homework


You must print this sheet out and write/type answers on it!

  1. Do a man -s2 exec. Explain why it is that exec only ever returns -1.
    
    
    	
  2. Read about execvp in APUE and/or the exec man page. Consider the following program, stdinwc:
     1 #include <stdio.h>
     2 #include <string.h>
     3 #include <unistd.h>
     4 
     5 int main()
     6 {
     7   char buff[128];
     8   char *newargv[32];
     9   int i = 0;
    10 
    11   newargv[i++] = "wc";
    12 
    13   while(fscanf(stdin,"%s",buff) > 0)
    14     newargv[i++] = strdup(buff);
    15 
    16   newargv[i++] = NULL;
    17 
    18   execvp("wc",newargv);
    19 
    20   return 0;
    21 }