Created
August 8, 2011 12:39
-
-
Save guohai/1131680 to your computer and use it in GitHub Desktop.
If a process is running
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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