Is there any differences between following two methods, for fork handling. I thought there exist no differnces but I saw some difference when using pipe (for reading file content)
Method 1:
pid = fork();
switch(pid) {
case -1:
eerrno = errno;
printf("fork error. %s(%d)n", strerror(errno), errno);
exit(eerrno);
case 0:
// ....
default:
// ...
wait(NULL);
}
Method 2:
if ( (pid = fork()) < 0) {
eerrno = errno;
printf("fork error. %s(%d)n", strerror(errno), errno);
exit(eerrno);
}
if (pid == 0)
// ....
else {
wait(NULL);
// ...
}