• Find the pid of the application launched by proxychains-ng.

    From hongyi.zhao@gmail.com@21:1/5 to All on Sun Sep 12 06:17:10 2021
    See the following example:

    $ proxychains-ng-http google-chrome >/dev/null 2>&1 &
    [1] 2226205
    $ wmctrl -lp | grep 'Google Chrome'
    0x00400020 0 1458872 X10DAi-00 New Tab - Google Chrome

    What's the relationship between 2226205 and 1458872? Is it possible to find the PID of the application, i.e., 1458872, launched by proxychains-ng based on the background proxychains-ng PID, i.e., 2226205?

    Regards,
    HY

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Kenny McCormack@21:1/5 to hongy...@gmail.com on Sun Sep 12 13:36:51 2021
    In article <32c46650-de8a-4c4d-9a84-0bfdf31e979fn@googlegroups.com>, hongy...@gmail.com <hongyi.zhao@gmail.com> wrote:
    See the following example:

    $ proxychains-ng-http google-chrome >/dev/null 2>&1 &
    [1] 2226205
    $ wmctrl -lp | grep 'Google Chrome'
    0x00400020 0 1458872 X10DAi-00 New Tab - Google Chrome

    What's the relationship between 2226205 and 1458872? Is it possible
    to find the PID of the application, i.e., 1458872, launched by
    proxychains-ng based on the background proxychains-ng PID, i.e., 2226205?

    I use the following shell function in my scripts:

    # usage: childpid=$(getpid <parentPid> <program2search4>)
    getpid() {
    pstree -p $1 | gawk 'NF > 1 { print $2+0 }' FS="-($2)[(]"
    }

    The idea is that you could just use "pidof" (or "pgrep" or whatever), but
    that searches globally - i.e., searches all the processes on the system.
    What you want is a version of "pidof" that only searches the children of a given process ID. The above function does that.

    P.S. Doncha just love these new 7_or_8-digit-PIDs? The system I'm typing
    on now recently upgraded to using them. Crazy, man!

    --
    Never, ever, ever forget that "Both sides do it" is strictly a Republican meme.

    It is always the side that sucks that insists on saying "Well, you suck, too".

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Janis Papanagnou@21:1/5 to hongy...@gmail.com on Sun Sep 12 15:28:06 2021
    On 12.09.2021 15:17, hongy...@gmail.com wrote:
    See the following example:

    $ proxychains-ng-http google-chrome >/dev/null 2>&1 & [1] 2226205 $
    wmctrl -lp | grep 'Google Chrome' 0x00400020 0 1458872 X10DAi-00 New
    Tab - Google Chrome

    What's the relationship between 2226205 and 1458872? Is it possible
    to find the PID of the application, i.e., 1458872, launched by
    proxychains-ng based on the background proxychains-ng PID, i.e.,
    2226205?

    If you are effectively asking whether you can find the parent of a
    process given the PIDs then yes, that's possible by using ps(1).

    $ ps -o ppid,pid
    PPID PID
    22673 14283
    22488 22673


    Janis


    Regards, HY


    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Janis Papanagnou@21:1/5 to Kenny McCormack on Sun Sep 12 15:44:30 2021
    On 12.09.2021 15:36, Kenny McCormack wrote:
    In article <32c46650-de8a-4c4d-9a84-0bfdf31e979fn@googlegroups.com>, hongy...@gmail.com <hongyi.zhao@gmail.com> wrote:
    See the following example:

    $ proxychains-ng-http google-chrome >/dev/null 2>&1 &
    [1] 2226205
    $ wmctrl -lp | grep 'Google Chrome'
    0x00400020 0 1458872 X10DAi-00 New Tab - Google Chrome

    What's the relationship between 2226205 and 1458872? Is it possible
    to find the PID of the application, i.e., 1458872, launched by
    proxychains-ng based on the background proxychains-ng PID, i.e., 2226205?

    I use the following shell function in my scripts:

    # usage: childpid=$(getpid <parentPid> <program2search4>)
    getpid() {
    pstree -p $1 | gawk 'NF > 1 { print $2+0 }' FS="-($2)[(]"
    }

    The idea is that you could just use "pidof" (or "pgrep" or whatever), but that searches globally - i.e., searches all the processes on the system.
    What you want is a version of "pidof" that only searches the children of a given process ID. The above function does that.

    What's the advantage of the complex pstree-based function compared to
    just using ps(1) ?

    $ ps h --ppid 22575 -o pid
    1764
    31254


    Janis

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Kenny McCormack@21:1/5 to janis_papanagnou@hotmail.com on Sun Sep 12 14:11:57 2021
    In article <shl07u$1amq$1@gioia.aioe.org>,
    Janis Papanagnou <janis_papanagnou@hotmail.com> wrote:
    ...
    What's the advantage of the complex pstree-based function compared to
    just using ps(1) ?

    $ ps h --ppid 22575 -o pid
    1764
    31254

    A couple of things come to mind:

    1) I think you and I read OP's requirements differently. So, we (you & I)
    seem to be solving different problems. Of course, only time will tell
    which of us (if any) read it correctly.

    2) ps is a mess. It has become such a joke over the years, trying to
    support every possible version that's ever been written, that I try to
    avoid it. I had no idea that any of the options you list above even
    existed (and I've been using Unix and ps for far too long...)

    --
    You are a dreadful man, Kenny, for all your ways are the ways of death.
    - Rick C Hodgin -

    (P.S. -> https://www.youtube.com/watch?v=sMmTkKz60W8)

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Janis Papanagnou@21:1/5 to Kenny McCormack on Sun Sep 12 20:03:34 2021
    On 12.09.2021 16:11, Kenny McCormack wrote:
    In article <shl07u$1amq$1@gioia.aioe.org>,
    Janis Papanagnou <janis_papanagnou@hotmail.com> wrote:
    ...
    What's the advantage of the complex pstree-based function compared to
    just using ps(1) ?

    $ ps h --ppid 22575 -o pid
    1764
    31254

    A couple of things come to mind:

    1) I think you and I read OP's requirements differently. So, we (you & I) seem to be solving different problems. Of course, only time will tell
    which of us (if any) read it correctly.

    I don't think so (but may be wrong). In my first post I just formulated
    it as seen from the children ("what is a process's parent" instead of
    "what are the children of a process"), because I think it's closer to
    the understanding that for every Unix process the parent can be directly identified. And ps(1) connects both from whichever perspective you want
    to see it.


    2) ps is a mess. It has become such a joke over the years, trying to
    support every possible version that's ever been written, that I try to
    avoid it. I had no idea that any of the options you list above even
    existed (and I've been using Unix and ps for far too long...)

    While ps was always a mess - I agree here - meanwhile they incorporated
    options from any variant plus maybe new ones and --long-option-versions.
    True. For the large Linux community this means in consequence that you
    find whatever you want! The very useful -o to define only those fields
    that you actually want stems from AIX and is so useful that you see
    similar behaving options now in other commands as well. The dash-less
    'h' is an old style one (that can be found in commands with an older
    history), here mixed with the dash-form options and the long-forms;
    there's often options available that suppress the output data header.
    That there's a --ppid (at least in Linux' ps version) I just suspected
    and indeed found it in the man page. Otherwise I would have resorted
    instead of
    ps h --ppid 22575 -o pid
    to the still very clear
    ps -o ppid,pid | awk '$1==22575 {print $2}'

    Actually I think that with the "specify desired output" -o option and
    the "define what you are refering to" --ppid option it supports very
    clean interfaces without ballast. Just imagine the (even greater) mess
    in former times where every platform has its own incompatible version.
    Now you have it all in one at least and need not resort to other tools
    in most cases.

    Where we indeed prefer different approaches is that I avoid parsing
    graphical tools (like pstree) when tools are available that provide
    easier parseable tabular data.

    Janis

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From hongyi.zhao@gmail.com@21:1/5 to Janis Papanagnou on Sun Sep 12 17:55:13 2021
    On Sunday, September 12, 2021 at 9:44:35 PM UTC+8, Janis Papanagnou wrote:
    On 12.09.2021 15:36, Kenny McCormack wrote:
    In article <32c46650-de8a-4c4d...@googlegroups.com>,
    hongy...@gmail.com <hongy...@gmail.com> wrote:
    See the following example:

    $ proxychains-ng-http google-chrome >/dev/null 2>&1 &
    [1] 2226205
    $ wmctrl -lp | grep 'Google Chrome'
    0x00400020 0 1458872 X10DAi-00 New Tab - Google Chrome

    What's the relationship between 2226205 and 1458872? Is it possible
    to find the PID of the application, i.e., 1458872, launched by
    proxychains-ng based on the background proxychains-ng PID, i.e., 2226205?

    I use the following shell function in my scripts:

    # usage: childpid=$(getpid <parentPid> <program2search4>)
    getpid() {
    pstree -p $1 | gawk 'NF > 1 { print $2+0 }' FS="-($2)[(]"
    }

    The idea is that you could just use "pidof" (or "pgrep" or whatever), but that searches globally - i.e., searches all the processes on the system. What you want is a version of "pidof" that only searches the children of a given process ID. The above function does that.
    What's the advantage of the complex pstree-based function compared to
    just using ps(1) ?

    $ ps h --ppid 22575 -o pid
    1764
    31254

    The wrapper script ``proxychains-ng-http'':

    #!/usr/bin/env bash
    proxychains_conf=/path/to/proxychains-ng-http.conf
    if type -fp proxychains4 >/dev/null; then
    exec proxychains4 -q -f $proxychains_conf "$@"
    fi


    The testing:

    werner@X10DAi-00:~$ proxychains-ng-http google-chrome >/dev/null 2>&1 &
    [1] 4069773
    0x00400031 0 3657396 X10DAi-00 New Tab - Google Chrome
    werner@X10DAi-00:~$ wmctrl -lp |grep -i 'chrome'
    0x00400031 0 3657396 X10DAi-00 New Tab - Google Chrome
    werner@X10DAi-00:~$ ps h --ppid 4069773 -o pid
    werner@X10DAi-00:~$

    HY

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From hongyi.zhao@gmail.com@21:1/5 to hongy...@gmail.com on Sun Sep 12 18:48:52 2021
    On Monday, September 13, 2021 at 8:55:16 AM UTC+8, hongy...@gmail.com wrote:
    On Sunday, September 12, 2021 at 9:44:35 PM UTC+8, Janis Papanagnou wrote:
    On 12.09.2021 15:36, Kenny McCormack wrote:
    In article <32c46650-de8a-4c4d...@googlegroups.com>,
    hongy...@gmail.com <hongy...@gmail.com> wrote:
    See the following example:

    $ proxychains-ng-http google-chrome >/dev/null 2>&1 &
    [1] 2226205
    $ wmctrl -lp | grep 'Google Chrome'
    0x00400020 0 1458872 X10DAi-00 New Tab - Google Chrome

    What's the relationship between 2226205 and 1458872? Is it possible
    to find the PID of the application, i.e., 1458872, launched by
    proxychains-ng based on the background proxychains-ng PID, i.e., 2226205?

    I use the following shell function in my scripts:

    # usage: childpid=$(getpid <parentPid> <program2search4>)
    getpid() {
    pstree -p $1 | gawk 'NF > 1 { print $2+0 }' FS="-($2)[(]"
    }

    The idea is that you could just use "pidof" (or "pgrep" or whatever), but that searches globally - i.e., searches all the processes on the system. What you want is a version of "pidof" that only searches the children of a
    given process ID. The above function does that.
    What's the advantage of the complex pstree-based function compared to
    just using ps(1) ?

    $ ps h --ppid 22575 -o pid
    1764
    31254
    The wrapper script ``proxychains-ng-http'':

    #!/usr/bin/env bash
    proxychains_conf=/path/to/proxychains-ng-http.conf
    if type -fp proxychains4 >/dev/null; then
    exec proxychains4 -q -f $proxychains_conf "$@"
    fi


    The testing:

    werner@X10DAi-00:~$ proxychains-ng-http google-chrome >/dev/null 2>&1 &
    [1] 4069773
    0x00400031 0 3657396 X10DAi-00 New Tab - Google Chrome
    werner@X10DAi-00:~$ wmctrl -lp |grep -i 'chrome'
    0x00400031 0 3657396 X10DAi-00 New Tab - Google Chrome
    werner@X10DAi-00:~$ ps h --ppid 4069773 -o pid
    werner@X10DAi-00:~$

    Got it. If there is already a Chrome session, it will be shared instead of creating a new session from scratch:

    $ pkill chrome
    $ proxychains-ng-http google-chrome >/dev/null 2>&1 &
    [2] 1097863
    $ wmctrl -lp |grep -i 'chrome'
    0x02000003 0 1097863 X10DAi-00 New Tab - Google Chrome

    HY

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)