Killing process in Shell Script

后端 未结 7 2043
囚心锁ツ
囚心锁ツ 2021-02-09 05:04

I have a very simple problem: When I run a shell script I start a program which runs in an infinite loop. After a while I wanna stop then this program before I can it again with

7条回答
  •  暖寄归人
    2021-02-09 05:36

    In bash $! expands to the PID of the last process started in the background. So you can do:

    ./app1 param1 &
    APP1PID=$!
    # ...
    kill $APP1PID
    

提交回复
热议问题