Skip to content

Instantly share code, notes, and snippets.

@guohai
Created August 8, 2011 12:39
Show Gist options
  • Select an option

  • Save guohai/1131680 to your computer and use it in GitHub Desktop.

Select an option

Save guohai/1131680 to your computer and use it in GitHub Desktop.
If a process is running
#!/bin/sh
PROC_HOME=$(cd "$(dirname "$0")"; pwd)
PID_FILE=$PROC_HOME/hello.pid
function alive() {
if [ -f ${PID_FILE} ] && ((`ps awux | grep -v grep | grep -c chrome`)); then
echo "the process is running"
exit 1
fi
echo "the process not running"
}
case "$1" in
alive)
alive
;;
*)
echo "Usage: $0 {alive}"
;;
esac
exit 0
# http://blog.163.com/crane02@126/blog/static/52055236201061781932562/
# if you use '#!/bin/sh' in ubuntu, an error is thrown out 'Syntax error: "(" unexpected'
# but if '#!/bin/sh', everything is ok
# maybe I use some features only bash has in this snippet
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment