is there any way to know the pid of a launched program?

前端 未结 2 1832
名媛妹妹
名媛妹妹 2021-01-02 06:44

if I launch a bash script as a child, I can pass its own pid to the parent by using $$.

Is there any way to find the pid of a program that I launch from a script in

相关标签:
2条回答
  • 2021-01-02 07:15

    Use this: $! right after executing the command whose PID you want. It means, though that you need to use an ampersand (&) after the command, to start it in background. E.g.:

    my_command & CMDPID=$!
    echo "$CMDPID"
    
    0 讨论(0)
  • 2021-01-02 07:31

    The variable $! has the PID of the last background process you started.

    0 讨论(0)
提交回复
热议问题