Killing process in Shell Script

后端 未结 7 2040
囚心锁ツ
囚心锁ツ 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:39

    In most shells (including Bourne and C), the PID of the last subprocess you launched in the background will be stored in the special variable $!.

    #!/bin/bash
    ./app1 &
    PID=$!
    # ...
    kill $PID
    

    There is some information here under the Special Variables section.

提交回复
热议问题