Thread: execlp() vs excelp < 0 error handling question

  1. #1
    Banned
    Join Date
    May 2007
    Location
    Berkeley, CA
    Posts
    329

    execlp() vs excelp < 0 error handling question

    What the difference in doing something like

    Code:
    int main(void) 
    { 
      pid_t pid; 
      int count; 
      for(count=0; count<5; count++) { 
        pid=fork(); 
        if (pid==0) { 
          /* child process */ 
          execlp("kedit", "kedit", (char *) NULL); 
          perror("exec failure"); 
          exit(1); 
        } 
      } 
      return 0; 
    
    }
    as opposed to say something like

    Code:
    int main(void) 
    { 
      pid_t pid; 
      int count; 
      for(count=0; count<5; count++) { 
        pid=fork(); 
        if (pid==0) { 
          /* child process */ 
          if((execlp("kedit", "kedit", (char *) NULL)) < 0){
            perror("exec failure"); 
            exit(1); 
          }
        } 
      } 
      return 0; 
    
    }

  2. #2
    Registered User
    Join Date
    Apr 2008
    Posts
    19
    My man page says that if any of the exec()'s return they will return error, so it seems that both of your programs are functionally identical.

  3. #3
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    The latter is clearer for programmers who don't fully understand the exec* family.

    Pointless, though, IMO.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. <( ' '<) Simple Programming Question?
    By strigen in forum C Programming
    Replies: 1
    Last Post: 03-05-2009, 03:17 PM
  2. I need help to compile this code...
    By wise_ron in forum C Programming
    Replies: 17
    Last Post: 05-07-2006, 12:22 PM
  3. another exercise question
    By luigi40 in forum C# Programming
    Replies: 3
    Last Post: 11-28-2005, 03:52 PM
  4. what does this warningmean???
    By kreyes in forum C Programming
    Replies: 5
    Last Post: 03-04-2002, 07:53 AM