In a bash script, I want to do the following (in pseudo-code):
if [ a process exists with $PID ]; then
kill $PID
fi
What’s the appropriate expression for the conditional statement?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
To check for the existence of a process, use
But just as @unwind said, if you want it to terminate in any case, then just
Otherwise you will have a race condition, where the process might have disappeared after the first
kill -0.If you want to ignore the text output of
killand do something based on the exit code, you can