C Board  

Go Back   C Board > Platform Specific Boards > Linux Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 06-27-2008, 06:56 PM   #1
Registered User
 
Join Date: May 2007
Location: Berkeley, CA
Posts: 140
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; 

}
Overworked_PhD is offline   Reply With Quote
Old 06-28-2008, 08:06 PM   #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.
birkelbach is offline   Reply With Quote
Old 06-29-2008, 04:33 AM   #3
Cat without Hat
 
CornedBee's Avatar
 
Join Date: Apr 2003
Posts: 8,492
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
CornedBee is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

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


All times are GMT -6. The time now is 10:59 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22