Live data from Hacker News

fork() can fail

rachelbythebay.com

1–10 of 320 posts

Re: fork() can fail

#2
This 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

#4

This 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.

Re: fork() can fail

#6
Quietly goes to check the last piece of C I wrote containing a fork():

    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
This reminds me of one of the most epic bugs I've ever run into:

    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

#9

This 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.

That's understandable, but please don't feed the trolls.

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.

Post reply on HN