News for hackers. Stuff that matters.
Re:How not to test that mysqld is alive by KC8ZKF on Monday October 05, 2009 @12:39PM (#862100)
'ps ax | grep [m]ysqld' (The regex '[f]oo' will match 'foo' but not itself.)
Re:How not to test that mysqld is alive by kree10 on Monday October 05, 2009 @01:31PM (#862205)
That's one of my favorite shell techniques.

Still, I think they're doing it wrong. For keeping daemons alive I rely on http://cr.yp.to/daemontools.html .

Re:How not to test that mysqld is alive by jrockway on Monday October 05, 2009 @04:22PM (#862687)
This is the correct answer -- when you fork the process yourself, you don't have to guess about it dying, you get SIGCHLD and can handle it accordingly.

If you use daemontools, this code is already written for you.

Re:How not to test that mysqld is alive by trapper on Tuesday October 06, 2009 @01:45AM (#863615)
Can you use daemontools to monitor/kill/restart processes that run out of memory but don't exit?
Re:How not to test that mysqld is alive by viraptor on Monday October 05, 2009 @08:14PM (#863173)
Don't... You will still see someone else's 'grep mysql' as well as yours 'man mysql' and any command that just happens to include that string :/
Re:How not to test that mysqld is alive by CrLf on Monday October 05, 2009 @02:47PM (#862442)
Well, but why does that work? Doesn't it rely on the opposite outcome of the race condition mentioned in the article?
Re:How not to test that mysqld is alive by sjs on Monday October 05, 2009 @03:26PM (#862547)
regex background: [abc] matches any of 'a', 'b', or 'c'. [m] matches only 'm'.

It works because the text to match is no longer included in the command line invoked to do the matching. Whether or not 'grep [m]ysqld' appears in the list produced by ps is irrelevant, as [m]ysqld does not match "m]ysqld". i.e. the 'm' matches, but then the match fails when it hits ']'.

tl;dr It's just a short way of matching "mysqld" without the matching pattern itself being "mysqld".

Re:How not to test that mysqld is alive by cracki on Monday October 05, 2009 @02:57PM (#862469)
nope. doesn't.
Re:How not to test that mysqld is alive by CrLf on Monday October 05, 2009 @03:27PM (#862550)
I guess it was I that fell into a race condition: replying before my brain had finished parsing the command. :)

It's obvious now, that regexp does not match, for example, the "]".