Skip to content
Advertisement

escape alarm() process timeout with nohup or setsid?

I have a monitoring application, Zabbix agent, that allows me to run arbitrary commands/scripts and grab the return value. The agent is configured with a timeout and any command that exceeds the timeout will be killed.

For every command that is run, it first sets the timeout via alarm(timeout) and then forks the agent process before running the command in a new shell via execl("/bin/sh", "sh", "-c", command, NULL).

I have an awkward scenario that i can’t adjust the agents config timeout to be greater than 2 seconds but the command i need to run will take 10-30 seconds.

So i was wondering if anyone knows some way that i can specify a command that when run can escape the timeout and run till completion. I was trying nohup or setsid thinking it wouldn’t inherit the timeout set in parent but it is still killed for some reason.

Here is my example.. the agent expects 1 to be returned within it’s timeout so i start my long running command in subshell and echo 1 immediately to appease it. The /opt/scripts/test/long_running.sh still gets killed though. I was hoping that running with nohup and in a subshell that it would escape the timeout.

UserParameter=my.test.cmd,nohup sh -c "(/opt/scripts/test/long_running.sh $1 &); echo 1"

Thanks for reading.

fLo

Advertisement

Answer

nohup typically squelches the output and prints something else, so the server might be seeing Redirecting output to nohup.out instead of the expected 1.

Try something like

echo 1; nohup sh -c "/opt/scripts/test/long_running.sh $1" >& /dev/null
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement