I have a script running in background like this:
nohup /tmp/a.sh &
If the script is running for more than 5 mins, I want to kill it.
-bash-3.2$ nohup /tmp/a.sh &
[1] 2518
-bash-3.2$ nohup: appending output to `nohup.out'
-bash-3.2$ ps -ef | grep /tmp/a.sh
ordev 2518 17827 0 15:24 pts/3 00:00:00 /bin/sh /tmp/a.sh
ordev 2525 17827 0 15:24 pts/3 00:00:00 grep /tmp/a.sh
-bash-3.2$
-bash-3.2$ killall /tmp/a.sh # killall not working like this
/tmp/a.sh: no process killed
If I use killall like below, it tries to kill all sessions running /bin/sh:
-bash-3.2$ killall sh /tmp/a.sh
sh(17822): Operation not permitted # this pid associated with another process under root user.
/tmp/a.sh: no process killed
[1]+ Terminated nohup /tmp/a.sh .
Other than pkill -f, are there any alternatives that kill only the required script name?
timeout 5m urcommandherepkill -f?nohup /tmp/a.sh &prints the pid. In your example, you could just dokill 2518at the end.killallis looking for something that matches the first arg for a process's CMD. For instance