Run the process in the background, complete the task, then run the process in the background

I have a script that looks like this:

pushd .
nohup java -jar test/selenium-server.jar > /dev/null 2>&1 &
cd web/code/protected/tests/
phpunit functional/
popd

Selenium servers should start for tests, however, after the phpunit command completes, I want to kill the selenium-server server that was running.

How can i do this?

+4
source share
3 answers

When the script is freed, a new shell instance is created. This means that jobsthe new script will not list any jobs running in the parent shell.

Since the server selenium-serveris the only background process created in the new script, it can be killed using

#The first job 
kill %1

or

#The last job Same as the first one
kill %-
+3
source

, PID , kill, .

pushd .
nohup java -jar test/selenium-server.jar > /dev/null 2>&1 &
serverPID=$!
cd web/code/protected/tests/
phpunit functional/
kill $serverPID
popd

, , :)

+10

Until you start some other process in the background - what you are not doing - you can use $! directly:

pushd .
nohup java -jar test/selenium-server.jar > /dev/null 2>&1 &
cd web/code/protected/tests/
phpunit functional/
kill $!
popd
0
source

All Articles