Linux Ask!

Linux Ask! is a Q & A web site specific for Linux related questions. Questions are collected, answered and audited by experienced Linux users.

Feb 062010
 

Wait for a process terminated

Answer:

wait command allow you to monitor the termination of a process and quit afterward.

It is very useful when you want to trigger some action when a particular process terminated.

E.g. Send an email when a long running process of PID 5870 terminated

#  wait 5870 && echo Finished | mail -s Task [email protected]
Feb 022010
 

Check the exit status of a command

Answer:

You can check the exit status of a command by checking the special variable $?

E.g.

# ls
# echo $?
0

# foo
-bash: foo: command not found

# echo $?
127

Non zero (e.g. 127) exit status mean the command failed to execute.