![]() |
| | #1 |
| Registered User Join Date: May 2007 Location: Berkeley, CA
Posts: 140
| execlp() vs excelp < 0 error handling question 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;
}
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 | |
| | #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 | |
| | #3 |
| Cat without Hat 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 | |
![]() |
| Thread Tools | |
| Display Modes | |
|
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 |