I want to write a script that simulates a proccess being interrupted for some reason.
So I try to run something that kills the process
something like this:
ssh -f localhost sleep 7;kill pid
call_function_from_another_script_that_runs_the_process
hoping that the ssh command will run in the background because of “-f”, and the kill commands will not be executed soon enough because of the sleep.
The problem is that sleep doesn’t take effect here. the kill is being executed right away.
if I run the ssh without -f, so the second line isn’t called and my process doesn’t run.
please assume that the second line is as it says – running a function from another script the runs the process. I cant “put that function in a script and run it” or something that changes other things that are already written.
Any idea?
thanks.
You don’t need to use
sshto run something in the background. Use this:Notice the “&” which puts the whole subshell in the background. Inside the subshell, first a
sleepis run, then akill.Incidentally, the reason why the
killcommand in your example takes effect right away is because that line of the script has two commands: “ssh -f localhost sleep 7” and “kill pid“, not one command (“sleep 7;kill pid“) inside an SSH session.