ps aux | grep [a]pache | wc -l
(because you use the character class, it doesn't find itself as what it searches for is different than its text)
pgrep httpd | wc -l
pgrep -c apache
pgrep: unknown option -- c
Usage: pgrep [-filnvx] [-d delim] [-G gid] [-g pgrp] [-P ppid] [-s sid] [-t tty]
[-U uid] [-u euid] pattern ...
kamloops$ uname -srNetBSD 5.99.42
kamloops$
edit: formatting.
I only use grep once or twice a month on average. Why do employers expect you to have every possibly relevant thing memorized? I hate it. </rant>
I've been meaning to make a web comic where software companies end up with Exactly the employees they interview for. Eg the boss asks "why the does the guy we hired keep solving project Euler problems all day?"
lsof|grep TCP|grep -Ei '(apache|httpd)|cut -f 1 -d ' '|sort|uniq|wc -l
apache -S 2>&1|grep server|wc -l
apache2ctl -S 2>&1|grep server|wc -l
are processes/threads really servers? His question was a bit ambiguous. I wouldn't have accepted that job position either. :)
ps aux | grep apache | grep -v grep | wc -l
A more succinct, albeit less portable, alternative is 'pgrep apache | wc -l'. (Or 'pgrep httpd | wc -l', depending on your apache commandline.)
ps aux | grep apache | wc -l
but this wrongly included the command I was typing. We were working on their dev server and I was typing the commands into the terminal. I got back 12 when the real answer was 11. He eventually showed me what I should have typed:
ps aux | grep apache | grep -v grep | wc -l
The grep -v screens out the line I had just typed which had "grep apache" in it. Of course, there are other ways to do this, but this was the first thing I thought of. Of my error, I thought that was somewhat minor, but this guy had recently been hired to clean up a sloppy programming department, so he was looking for programmers who were flawless.
The other 2 tests at the other 2 jobs covered the usual questions (write a JOIN statement, write a sub-query, what is the difference between GET and POST?). On one of the interviews, 2 programmers came in to talk to me and they gave me a short PHP script which was working but which was badly written. They asked me how I would re-write it. Easy enough.
My sense is there is a lot of hiring going on in New York City. Possibly not enough local talent to fill all the jobs, but the businesses are here for other reasons (other than programming talent) so I think eventually programming talent from elsewhere will get drawn to New York City. There are some cities in the USA that are in deep economic decline, and will probably remain so for the next 5 years, so perhaps some of the programmers from those cities will migrate to New York City.