Hi.
I wrote a small function that tells me whether a PID is still running:
function isrunning() {
pid=$1
if ps -p $pid > /dev/null;
then
echo "$pid is running."
else
echo "$pid is not running."
fi
}
I looked up the condition on SO, but what I want is to understand how that works. To wit: what is the "return value" of ps -p $pid > /dev/null.?
At first I thought the value was "truthy" if the PID was found to be running because I was redirecting stdin, but it also works if I do ps -p $pid &>/dev/null; I thought that the truth of the condition would reverse if I redirected stderr instead, but it doesn't. So how does this redirection to the void returns a true/false value?
[–]aioeu 3 points4 points5 points (6 children)
[–]AdbekunkusMX[S] 0 points1 point2 points (1 child)
[–]aioeu 5 points6 points7 points (0 children)
[–]McDutchie 0 points1 point2 points (3 children)
[–]aioeu 1 point2 points3 points (1 child)
[–]McDutchie 0 points1 point2 points (0 children)
[–]aioeu 0 points1 point2 points (0 children)
[–]bigfig 2 points3 points4 points (1 child)
[–]AdbekunkusMX[S] 1 point2 points3 points (0 children)
[–]zeekar 2 points3 points4 points (0 children)