Skip to main content
Added an awk to extract and save the required Pid.
Source Link
Paul_Pedant
  • 9.4k
  • 3
  • 24
  • 27

$! should be the pid of the subshell. Try pstree -p $! to see if the information you need is in the list.

You may need to parse it (maybe in awk), and the output to a pipe is different to what you see on screen.

Example from my login shell. You should see one ffmpeg in your list.

paul $ pstree -p $PPID | cat -vet
mate-terminal(6849)-+-bash(6856)---vi(9107)$
                    |-bash(7338)$
                    |-bash(9456)-+-cat(10573)$
                    |            `-pstree(10572)$
                    |-{dconf worker}(6855)$
                    |-{gdbus}(6854)$
                    `-{gmain}(6852)$
paul $

You may need to download pstree from the Mac Store: http://macappstore.org/pstree/

Typical awk ending to store the Pid in a variable would be:

Pid=$( pstree -p $PPID | awk -v 'RS=)' -v 'FS=(' '/ffmpeg/ { print $NF }' )

$! should be the pid of the subshell. Try pstree -p $! to see if the information you need is in the list.

You may need to parse it (maybe in awk), and the output to a pipe is different to what you see on screen.

Example from my login shell. You should see one ffmpeg in your list.

paul $ pstree -p $PPID | cat -vet
mate-terminal(6849)-+-bash(6856)---vi(9107)$
                    |-bash(7338)$
                    |-bash(9456)-+-cat(10573)$
                    |            `-pstree(10572)$
                    |-{dconf worker}(6855)$
                    |-{gdbus}(6854)$
                    `-{gmain}(6852)$
paul $

You may need to download pstree from the Mac Store: http://macappstore.org/pstree/

$! should be the pid of the subshell. Try pstree -p $! to see if the information you need is in the list.

You may need to parse it (maybe in awk), and the output to a pipe is different to what you see on screen.

Example from my login shell. You should see one ffmpeg in your list.

paul $ pstree -p $PPID | cat -vet
mate-terminal(6849)-+-bash(6856)---vi(9107)$
                    |-bash(7338)$
                    |-bash(9456)-+-cat(10573)$
                    |            `-pstree(10572)$
                    |-{dconf worker}(6855)$
                    |-{gdbus}(6854)$
                    `-{gmain}(6852)$
paul $

You may need to download pstree from the Mac Store: http://macappstore.org/pstree/

Typical awk ending to store the Pid in a variable would be:

Pid=$( pstree -p $PPID | awk -v 'RS=)' -v 'FS=(' '/ffmpeg/ { print $NF }' )
Source Link
Paul_Pedant
  • 9.4k
  • 3
  • 24
  • 27

$! should be the pid of the subshell. Try pstree -p $! to see if the information you need is in the list.

You may need to parse it (maybe in awk), and the output to a pipe is different to what you see on screen.

Example from my login shell. You should see one ffmpeg in your list.

paul $ pstree -p $PPID | cat -vet
mate-terminal(6849)-+-bash(6856)---vi(9107)$
                    |-bash(7338)$
                    |-bash(9456)-+-cat(10573)$
                    |            `-pstree(10572)$
                    |-{dconf worker}(6855)$
                    |-{gdbus}(6854)$
                    `-{gmain}(6852)$
paul $

You may need to download pstree from the Mac Store: http://macappstore.org/pstree/