fork() can fail
rachelbythebay.com
fork() can fail
1–10 of 320 posts
Re: fork() can fail
#2Re: fork() can fail
#3Re: fork() can fail
#4This is an important point, along similar lines to something we discussed at work today in a code review. The programmer in question assumed that all and every request for the resources consumed would always work. Literally, no testing or consideration for what if one of those request fails. Will be emailing them this article tomorrow!
Re: fork() can fail
#5Thanks for providing an impetus to do so.
Re: fork() can fail
#6 if (daemon && !test_mode) {
int pid = fork();
if (pid == -1) {
fatal_error("Failed to fork");
}
if (pid != 0) {
write_pid(pid_file, pid, !test_mode);
exit(0);
}
} else {
write_pid(pid_file, getpid(), !test_mode);
}
Phew!Re: fork() can fail
#7 mkdir("/foo", 0700);
chdir("/foo");
recursively_delete_everything_in_current_directory();
Running as root, this usually worked fine: It would create a directory, move into it, and clean out any garbage left behind by a previous run before doing anything new.Running as non-root, the mkdir failed, the chdir failed, and it started eating my home directory.
Re: fork() can fail
#8 #include
int main(void)
{
while(1) {
fork();
}
}Re: fork() can fail
#9This is an important point, along similar lines to something we discussed at work today in a code review. The programmer in question assumed that all and every request for the resources consumed would always work. Literally, no testing or consideration for what if one of those request fails. Will be emailing them this article tomorrow!
Your username is offensive. I'd like to take what you say seriously, and perhaps even engage in further conversation about the topic at hand, but ... you know ... you look stupid. Grow up. You should be embarrassed.
When you see a comment that is truly bad for HN, it's best to flag it. You can do this by clicking on "link" to go to the item page for the comment, then "flag". We monitor those flags and take action based on them.