简体   繁体   中英

Run and kill java program in background in Linux

i have a little java program that i want to run in background (i don't want to block the cli). I want also have the possibility to kill it (without looking manually for the PID). I want to create to script: ./start.sh -> starts the java program in background ./stop.sh -> try to kill the java program (running in background).

Any ideas ?

start.sh:

javaProgram &
pid=$!
echo $pid >/var/run/javaProgram.pid

stop.sh:

kill $(cat /var/run/javaProgram.pid)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM