3 ms·
My most memorable fork-related cockup was in 1999ish. I was working on a program to purge cache entries from a web server’s front-end proxies when users uploade
by fanf2 7y ago
My most memorable fork-related cockup was in 1999ish. I was working on a program to purge cache entries from a web server’s front-end proxies when users uploaded or deleted files. At one point I redid the restart/daemonize logic and I got a condition backwards. The result was that when the daemon received a restart signal it went into a loop, repeatedly forking - but it wasn’t a fork bomb: the parent immediately died and the child looped to fork and die, etc., so only one was running at a time.
In most situations this would have been OK, but it was running as root on a production server. So I could not (for example) kill all my processes with kill -9 -1 because that would have killed the machine.
So the pid of my errant program was counting up quite fast. I tried finding it in the output of ps then running while !kill $pid; do :; done for a slightly bigger $pid, hoping that my program would be killed when its pid reached $pid - nope, it won the race, and forked right past the kill loop. I tried rewriting the kill loop in C and the problem program still won the race.
In the end I needed to run several copies of the C kill loop on consecutive pids in order to kill the problem program as it forked through the kill zone. The collateral damage was only a few ftp login attempts...