How to run a program and know its PID in Linux?
If I have several shells running each other, will they all have separate PIDs?
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.
Greg’s wiki to the rescue:
$!is the PID of the last backgrounded process.kill -0 $PIDchecks whether$PIDis still running. Only use this for processes started by the current process or its descendants, otherwise the PID could have been recycled.waitwaits for all children to exit before continuing.Actually, just read the link – It’s all there (and more).
$$is the PID of the current shell.And yes, each shell will have its own PID (unless it’s some homebrewed shell which doesn’t
forkto create a “new” shell).