The content of startTest.sh is as follows: #!/bin/sh java -jar Test.jar & #Note: There must be & let it execute in the background, otherwise no pid will be generated echo $! > java.pid # Write the pid corresponding to the start of the jar package to the file, and provide the pid when it stops The content of stopTest.sh is as follows: #!/bin/sh PID=$(cat java.pid ) kill -9 $PID