3 ms·
This isn't really fork() failing per se -- but rather a failed program/script that did not understand the well defined and clearly documented behavior of fork()
by Alupis 12y ago
This isn't really fork() failing per se -- but rather a failed program/script that did not understand the well defined and clearly documented behavior of fork().
- dllthomas 12y agoThe man page says, "On failure, -1 is returned in the parent, no process is created, and errno is set appropriately." So if fork is behaving as documented, returning -1 is because of "fork failing".
- Alupis 12y agoTrue -- I guess fork() has failed at that point. I was more getting at the article's authors scenarios of careless scripts treating -1 as a valid pid (which should always be > 0), which would be a failure of the script instead.
- dllthomas 12y agoWell, it's a failure of the script and the POSIX API - it is unfortunate that a pid_t inhabited by -1 means "failure" in one case and "everything" in another. It is certainly not fork, narrowly, to blame.
- M00n_Sl47r 12y agoI think the point that the author was making, outside of any criticism to the API itself, is that the hapless programmer may not know that fork() could even return -1. The article is pointing out that possibility as documented by the API, not criticizing a failure of the API. Whether or not the API is faulty in this--and I tend to agree with you--is outside of the scope of the article, though only just.
- dllthomas 12y agoI wasn't making any particular comment on the content of the article. It was certainly relevant to the discussion tangent the thread had wandered down.
- brazzy 12y agoPsst - it's "per se"...
- Alupis 12y ago;-P
- bostonpete 12y ago¿Por qué?
- Alupis 12y agoI originally had "per-say" instead of the correct "per se"
- yosefk 12y agoTaking the square root of a negative number removing all the files in your home directory could be "well defined and clearly documented behavior". Would you blame the API author at that point or would it still be strictly your fault? At what point do API authors share the blame for a needlessly harsh punishment delivered upon a predictably common error? I certainly prefer to work with systems produced by people tending to think it'd be their fault more often than not.
- Alupis 12y agoI could argue, however, that in this particular case, it's the user's fault for failing to understand the full and defined behavior of fork() in addition to failing to understand the full and defined behavior of other functions, ...say, kill(). It's just as wrong to feed kill() -1 as it would be to feed it -48585 or "babdkd" (unless that is explicitly your intention). A simple sanity check of if [ "${pid} > "0" ]; is all that's necessary to protect against this behavior. So, I would argue, the fault lays on the users, not the creator, for not understanding the API when all materials necessary to understand said API are freely available. (with that said, I think it's safe to say, we've all been bitten by not fully understanding some function before)
- ajkjk 12y agoThere'd be far fewer bugs if everyone knew exactly how everything else works. This kind of mistake is godawful and should not be defended. (but it's correctly fixed through stronger typing, not through choosing -48585 as the code for killing everything).
- Alupis 12y ago> not through choosing -48585 as the code for killing everything) Actually, only -1 is the code that "kills everything" > There'd be far fewer bugs if everyone knew exactly how everything else works. Perhaps I misinterpreted your meaning, because you seem to be advocating using programming and scripting languages without actually bothering to learn them. Of course this can, will and does lead to very bad effects. The bottom line is, if you are going to use a function in your program/script -- please, read the docs and understand what is will return at the very least.