in reply to Re: Re: Why won't it die??
in thread Why won't it die??

Using system is a question of economy here. With the backticks, you capture the command's output - only to throw it away. The system(LIST) form also avoids invoking the shell. Actually, if you were interpolating user input into the call, avoiding the shell via system(LIST) increases security as well, because you don't have to worry about shell metacharacters, but that's not the case here.

The benefit of storing the output from ps is twofold. First of all, you only need to call the program once, as opposed to twice. And then you can use Perl's own grep to search that data - as opposed to spawning a process for the grep binary, twice. What grep really returns is a list of all the list that matched, but we're not storing it. Using a list in an if condition simply checks if the list is empty or not, and that's what we do here.

Btw, have another look at the post. The first time around, I forgot another detail: I wasn't checking for whether the system calls succeed. Stupid omission now fixed..

Makeshifts last the longest.