How to view the names all child processes spawned by a program

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
0
down vote

favorite
1












(TLDR Doug O'Neal's strace -f -e execve ./myprogram solved me problem)



I start a program on the command line. The executing program spawns processes. I would like to see or log the names of all processes spawned by the program.



Details



I've tried top with forest view V:



$ top -c -d 1


Only the parent program is briefly visible. I suspect the refresh rate is too slow to show the child processes.



I've tried to filter by COMMAND=myprogram but this most probably filters out the child processes.



The parent program spawns processes but I am not sure if top's forest view will show those new processes indented under the original process or independently. I'm not sure if a spawned process can be independent of the parent.



Update #1



I tried this answer with the sleep removed.



#!/bin/bash

mkdir -p "$HOME/ps_logs"

while true; do
ps faux > "$HOME/ps_logs/ps_$(date +%Y-%m-%d_%H:%M:%S).log"
done


I filtered the output with:



grep -rnw './' -e 'myprogam'


All the files only contain myprogram. So how do I know if myprogram even spawns any processes?







share|improve this question





















  • Have you tried pstree?
    – steeldriver
    Jul 5 at 12:08










  • How should I employ pstree? The program I'm analysing finishes in under a second. pstree shows running processes. I'm looking for something that logs the spawned processes as the program runs.
    – robor78
    Jul 5 at 12:13











  • Well you could background the parent, and use $! to immediately get its PID to pass to pstree e.g. ./yourprog & pstree -p $!
    – steeldriver
    Jul 5 at 12:24






  • 2




    Maybe strace -f -e execve ./myprogram ? Doesn't have the problem of trying to shell out another command before your program actually exits.
    – Doug O'Neal
    Jul 5 at 12:53






  • 1




    Yeah or see How to track child process using strace?
    – steeldriver
    Jul 5 at 12:56














up vote
0
down vote

favorite
1












(TLDR Doug O'Neal's strace -f -e execve ./myprogram solved me problem)



I start a program on the command line. The executing program spawns processes. I would like to see or log the names of all processes spawned by the program.



Details



I've tried top with forest view V:



$ top -c -d 1


Only the parent program is briefly visible. I suspect the refresh rate is too slow to show the child processes.



I've tried to filter by COMMAND=myprogram but this most probably filters out the child processes.



The parent program spawns processes but I am not sure if top's forest view will show those new processes indented under the original process or independently. I'm not sure if a spawned process can be independent of the parent.



Update #1



I tried this answer with the sleep removed.



#!/bin/bash

mkdir -p "$HOME/ps_logs"

while true; do
ps faux > "$HOME/ps_logs/ps_$(date +%Y-%m-%d_%H:%M:%S).log"
done


I filtered the output with:



grep -rnw './' -e 'myprogam'


All the files only contain myprogram. So how do I know if myprogram even spawns any processes?







share|improve this question





















  • Have you tried pstree?
    – steeldriver
    Jul 5 at 12:08










  • How should I employ pstree? The program I'm analysing finishes in under a second. pstree shows running processes. I'm looking for something that logs the spawned processes as the program runs.
    – robor78
    Jul 5 at 12:13











  • Well you could background the parent, and use $! to immediately get its PID to pass to pstree e.g. ./yourprog & pstree -p $!
    – steeldriver
    Jul 5 at 12:24






  • 2




    Maybe strace -f -e execve ./myprogram ? Doesn't have the problem of trying to shell out another command before your program actually exits.
    – Doug O'Neal
    Jul 5 at 12:53






  • 1




    Yeah or see How to track child process using strace?
    – steeldriver
    Jul 5 at 12:56












up vote
0
down vote

favorite
1









up vote
0
down vote

favorite
1






1





(TLDR Doug O'Neal's strace -f -e execve ./myprogram solved me problem)



I start a program on the command line. The executing program spawns processes. I would like to see or log the names of all processes spawned by the program.



Details



I've tried top with forest view V:



$ top -c -d 1


Only the parent program is briefly visible. I suspect the refresh rate is too slow to show the child processes.



I've tried to filter by COMMAND=myprogram but this most probably filters out the child processes.



The parent program spawns processes but I am not sure if top's forest view will show those new processes indented under the original process or independently. I'm not sure if a spawned process can be independent of the parent.



Update #1



I tried this answer with the sleep removed.



#!/bin/bash

mkdir -p "$HOME/ps_logs"

while true; do
ps faux > "$HOME/ps_logs/ps_$(date +%Y-%m-%d_%H:%M:%S).log"
done


I filtered the output with:



grep -rnw './' -e 'myprogam'


All the files only contain myprogram. So how do I know if myprogram even spawns any processes?







share|improve this question













(TLDR Doug O'Neal's strace -f -e execve ./myprogram solved me problem)



I start a program on the command line. The executing program spawns processes. I would like to see or log the names of all processes spawned by the program.



Details



I've tried top with forest view V:



$ top -c -d 1


Only the parent program is briefly visible. I suspect the refresh rate is too slow to show the child processes.



I've tried to filter by COMMAND=myprogram but this most probably filters out the child processes.



The parent program spawns processes but I am not sure if top's forest view will show those new processes indented under the original process or independently. I'm not sure if a spawned process can be independent of the parent.



Update #1



I tried this answer with the sleep removed.



#!/bin/bash

mkdir -p "$HOME/ps_logs"

while true; do
ps faux > "$HOME/ps_logs/ps_$(date +%Y-%m-%d_%H:%M:%S).log"
done


I filtered the output with:



grep -rnw './' -e 'myprogam'


All the files only contain myprogram. So how do I know if myprogram even spawns any processes?









share|improve this question












share|improve this question




share|improve this question








edited Jul 6 at 7:50
























asked Jul 5 at 11:42









robor78

1014




1014











  • Have you tried pstree?
    – steeldriver
    Jul 5 at 12:08










  • How should I employ pstree? The program I'm analysing finishes in under a second. pstree shows running processes. I'm looking for something that logs the spawned processes as the program runs.
    – robor78
    Jul 5 at 12:13











  • Well you could background the parent, and use $! to immediately get its PID to pass to pstree e.g. ./yourprog & pstree -p $!
    – steeldriver
    Jul 5 at 12:24






  • 2




    Maybe strace -f -e execve ./myprogram ? Doesn't have the problem of trying to shell out another command before your program actually exits.
    – Doug O'Neal
    Jul 5 at 12:53






  • 1




    Yeah or see How to track child process using strace?
    – steeldriver
    Jul 5 at 12:56
















  • Have you tried pstree?
    – steeldriver
    Jul 5 at 12:08










  • How should I employ pstree? The program I'm analysing finishes in under a second. pstree shows running processes. I'm looking for something that logs the spawned processes as the program runs.
    – robor78
    Jul 5 at 12:13











  • Well you could background the parent, and use $! to immediately get its PID to pass to pstree e.g. ./yourprog & pstree -p $!
    – steeldriver
    Jul 5 at 12:24






  • 2




    Maybe strace -f -e execve ./myprogram ? Doesn't have the problem of trying to shell out another command before your program actually exits.
    – Doug O'Neal
    Jul 5 at 12:53






  • 1




    Yeah or see How to track child process using strace?
    – steeldriver
    Jul 5 at 12:56















Have you tried pstree?
– steeldriver
Jul 5 at 12:08




Have you tried pstree?
– steeldriver
Jul 5 at 12:08












How should I employ pstree? The program I'm analysing finishes in under a second. pstree shows running processes. I'm looking for something that logs the spawned processes as the program runs.
– robor78
Jul 5 at 12:13





How should I employ pstree? The program I'm analysing finishes in under a second. pstree shows running processes. I'm looking for something that logs the spawned processes as the program runs.
– robor78
Jul 5 at 12:13













Well you could background the parent, and use $! to immediately get its PID to pass to pstree e.g. ./yourprog & pstree -p $!
– steeldriver
Jul 5 at 12:24




Well you could background the parent, and use $! to immediately get its PID to pass to pstree e.g. ./yourprog & pstree -p $!
– steeldriver
Jul 5 at 12:24




2




2




Maybe strace -f -e execve ./myprogram ? Doesn't have the problem of trying to shell out another command before your program actually exits.
– Doug O'Neal
Jul 5 at 12:53




Maybe strace -f -e execve ./myprogram ? Doesn't have the problem of trying to shell out another command before your program actually exits.
– Doug O'Neal
Jul 5 at 12:53




1




1




Yeah or see How to track child process using strace?
– steeldriver
Jul 5 at 12:56




Yeah or see How to track child process using strace?
– steeldriver
Jul 5 at 12:56










1 Answer
1






active

oldest

votes

















up vote
1
down vote













I generally like using ps auxf because it visually shows the child processes under the parent visually:



$ ps auxf
...
root 637 0.0 0.0 110044 800 tty1 Ss+ 02:50 0:00 /sbin/agetty --noclear tty1 linux
root 983 0.0 0.1 404028 1136 ? Sl 02:50 0:11 /usr/sbin/VBoxService --pidfile /var/run/vboxadd-service.sh
root 1013 0.0 1.6 562416 16444 ? Ssl 02:50 0:03 /usr/bin/python -Es /usr/sbin/tuned -l -P
root 1015 0.0 0.4 105996 4108 ? Ss 02:50 0:00 /usr/sbin/sshd -D
root 20191 0.0 0.5 152116 5576 ? Ss 10:06 0:00 _ sshd: vagrant [priv]
vagrant 20193 0.0 0.2 152304 2872 ? S 10:06 0:00 _ sshd: vagrant@pts/0
vagrant 20194 0.0 0.2 115964 2644 pts/0 Ss 10:06 0:00 _ -bash
root 20232 0.0 0.2 201844 2956 pts/0 S 10:06 0:00 _ sudo -Es
root 20233 0.0 0.2 116208 2964 pts/0 S 10:06 0:00 _ /bin/bash
root 20510 0.0 0.1 151240 1932 pts/0 R+ 11:01 0:00 _ ps auxf
root 1115 0.0 0.2 91628 2192 ? Ss 02:50 0:00 /usr/libexec/postfix/master -w
postfix 1117 0.0 0.3 91800 4048 ? S 02:50 0:00 _ qmgr -l -t unix -u
postfix 20149 0.0 0.3 91776 4048 ? S 09:39 0:00 _ pickup -l -t unix -u
...


Additionally if you just want to view the list of PID + PGID you can use ps with these switches like so:



$ ps x -o "%p %r %c"
PID PGID COMMAND
1 1 systemd
2 0 kthreadd
3 0 ksoftirqd/0
5 0 kworker/0:0H
7 0 migration/0
8 0 rcu_bh
...
...
591 591 rngd
594 594 systemd-logind
596 596 smartd
597 597 rsyslogd
600 600 acpid
616 616 abrtd
617 617 abrt-watch-log
630 630 atd
637 637 agetty
983 981 VBoxService
1013 1013 tuned
1015 1015 sshd
1115 1115 master
2426 2426 NetworkManager
2439 2439 dhclient
3123 3123 firewalld
3828 0 kworker/u2:1





share|improve this answer





















    Your Answer







    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "106"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    convertImagesToLinks: false,
    noModals: false,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );








     

    draft saved


    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f453602%2fhow-to-view-the-names-all-child-processes-spawned-by-a-program%23new-answer', 'question_page');

    );

    Post as a guest






























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    1
    down vote













    I generally like using ps auxf because it visually shows the child processes under the parent visually:



    $ ps auxf
    ...
    root 637 0.0 0.0 110044 800 tty1 Ss+ 02:50 0:00 /sbin/agetty --noclear tty1 linux
    root 983 0.0 0.1 404028 1136 ? Sl 02:50 0:11 /usr/sbin/VBoxService --pidfile /var/run/vboxadd-service.sh
    root 1013 0.0 1.6 562416 16444 ? Ssl 02:50 0:03 /usr/bin/python -Es /usr/sbin/tuned -l -P
    root 1015 0.0 0.4 105996 4108 ? Ss 02:50 0:00 /usr/sbin/sshd -D
    root 20191 0.0 0.5 152116 5576 ? Ss 10:06 0:00 _ sshd: vagrant [priv]
    vagrant 20193 0.0 0.2 152304 2872 ? S 10:06 0:00 _ sshd: vagrant@pts/0
    vagrant 20194 0.0 0.2 115964 2644 pts/0 Ss 10:06 0:00 _ -bash
    root 20232 0.0 0.2 201844 2956 pts/0 S 10:06 0:00 _ sudo -Es
    root 20233 0.0 0.2 116208 2964 pts/0 S 10:06 0:00 _ /bin/bash
    root 20510 0.0 0.1 151240 1932 pts/0 R+ 11:01 0:00 _ ps auxf
    root 1115 0.0 0.2 91628 2192 ? Ss 02:50 0:00 /usr/libexec/postfix/master -w
    postfix 1117 0.0 0.3 91800 4048 ? S 02:50 0:00 _ qmgr -l -t unix -u
    postfix 20149 0.0 0.3 91776 4048 ? S 09:39 0:00 _ pickup -l -t unix -u
    ...


    Additionally if you just want to view the list of PID + PGID you can use ps with these switches like so:



    $ ps x -o "%p %r %c"
    PID PGID COMMAND
    1 1 systemd
    2 0 kthreadd
    3 0 ksoftirqd/0
    5 0 kworker/0:0H
    7 0 migration/0
    8 0 rcu_bh
    ...
    ...
    591 591 rngd
    594 594 systemd-logind
    596 596 smartd
    597 597 rsyslogd
    600 600 acpid
    616 616 abrtd
    617 617 abrt-watch-log
    630 630 atd
    637 637 agetty
    983 981 VBoxService
    1013 1013 tuned
    1015 1015 sshd
    1115 1115 master
    2426 2426 NetworkManager
    2439 2439 dhclient
    3123 3123 firewalld
    3828 0 kworker/u2:1





    share|improve this answer

























      up vote
      1
      down vote













      I generally like using ps auxf because it visually shows the child processes under the parent visually:



      $ ps auxf
      ...
      root 637 0.0 0.0 110044 800 tty1 Ss+ 02:50 0:00 /sbin/agetty --noclear tty1 linux
      root 983 0.0 0.1 404028 1136 ? Sl 02:50 0:11 /usr/sbin/VBoxService --pidfile /var/run/vboxadd-service.sh
      root 1013 0.0 1.6 562416 16444 ? Ssl 02:50 0:03 /usr/bin/python -Es /usr/sbin/tuned -l -P
      root 1015 0.0 0.4 105996 4108 ? Ss 02:50 0:00 /usr/sbin/sshd -D
      root 20191 0.0 0.5 152116 5576 ? Ss 10:06 0:00 _ sshd: vagrant [priv]
      vagrant 20193 0.0 0.2 152304 2872 ? S 10:06 0:00 _ sshd: vagrant@pts/0
      vagrant 20194 0.0 0.2 115964 2644 pts/0 Ss 10:06 0:00 _ -bash
      root 20232 0.0 0.2 201844 2956 pts/0 S 10:06 0:00 _ sudo -Es
      root 20233 0.0 0.2 116208 2964 pts/0 S 10:06 0:00 _ /bin/bash
      root 20510 0.0 0.1 151240 1932 pts/0 R+ 11:01 0:00 _ ps auxf
      root 1115 0.0 0.2 91628 2192 ? Ss 02:50 0:00 /usr/libexec/postfix/master -w
      postfix 1117 0.0 0.3 91800 4048 ? S 02:50 0:00 _ qmgr -l -t unix -u
      postfix 20149 0.0 0.3 91776 4048 ? S 09:39 0:00 _ pickup -l -t unix -u
      ...


      Additionally if you just want to view the list of PID + PGID you can use ps with these switches like so:



      $ ps x -o "%p %r %c"
      PID PGID COMMAND
      1 1 systemd
      2 0 kthreadd
      3 0 ksoftirqd/0
      5 0 kworker/0:0H
      7 0 migration/0
      8 0 rcu_bh
      ...
      ...
      591 591 rngd
      594 594 systemd-logind
      596 596 smartd
      597 597 rsyslogd
      600 600 acpid
      616 616 abrtd
      617 617 abrt-watch-log
      630 630 atd
      637 637 agetty
      983 981 VBoxService
      1013 1013 tuned
      1015 1015 sshd
      1115 1115 master
      2426 2426 NetworkManager
      2439 2439 dhclient
      3123 3123 firewalld
      3828 0 kworker/u2:1





      share|improve this answer























        up vote
        1
        down vote










        up vote
        1
        down vote









        I generally like using ps auxf because it visually shows the child processes under the parent visually:



        $ ps auxf
        ...
        root 637 0.0 0.0 110044 800 tty1 Ss+ 02:50 0:00 /sbin/agetty --noclear tty1 linux
        root 983 0.0 0.1 404028 1136 ? Sl 02:50 0:11 /usr/sbin/VBoxService --pidfile /var/run/vboxadd-service.sh
        root 1013 0.0 1.6 562416 16444 ? Ssl 02:50 0:03 /usr/bin/python -Es /usr/sbin/tuned -l -P
        root 1015 0.0 0.4 105996 4108 ? Ss 02:50 0:00 /usr/sbin/sshd -D
        root 20191 0.0 0.5 152116 5576 ? Ss 10:06 0:00 _ sshd: vagrant [priv]
        vagrant 20193 0.0 0.2 152304 2872 ? S 10:06 0:00 _ sshd: vagrant@pts/0
        vagrant 20194 0.0 0.2 115964 2644 pts/0 Ss 10:06 0:00 _ -bash
        root 20232 0.0 0.2 201844 2956 pts/0 S 10:06 0:00 _ sudo -Es
        root 20233 0.0 0.2 116208 2964 pts/0 S 10:06 0:00 _ /bin/bash
        root 20510 0.0 0.1 151240 1932 pts/0 R+ 11:01 0:00 _ ps auxf
        root 1115 0.0 0.2 91628 2192 ? Ss 02:50 0:00 /usr/libexec/postfix/master -w
        postfix 1117 0.0 0.3 91800 4048 ? S 02:50 0:00 _ qmgr -l -t unix -u
        postfix 20149 0.0 0.3 91776 4048 ? S 09:39 0:00 _ pickup -l -t unix -u
        ...


        Additionally if you just want to view the list of PID + PGID you can use ps with these switches like so:



        $ ps x -o "%p %r %c"
        PID PGID COMMAND
        1 1 systemd
        2 0 kthreadd
        3 0 ksoftirqd/0
        5 0 kworker/0:0H
        7 0 migration/0
        8 0 rcu_bh
        ...
        ...
        591 591 rngd
        594 594 systemd-logind
        596 596 smartd
        597 597 rsyslogd
        600 600 acpid
        616 616 abrtd
        617 617 abrt-watch-log
        630 630 atd
        637 637 agetty
        983 981 VBoxService
        1013 1013 tuned
        1015 1015 sshd
        1115 1115 master
        2426 2426 NetworkManager
        2439 2439 dhclient
        3123 3123 firewalld
        3828 0 kworker/u2:1





        share|improve this answer













        I generally like using ps auxf because it visually shows the child processes under the parent visually:



        $ ps auxf
        ...
        root 637 0.0 0.0 110044 800 tty1 Ss+ 02:50 0:00 /sbin/agetty --noclear tty1 linux
        root 983 0.0 0.1 404028 1136 ? Sl 02:50 0:11 /usr/sbin/VBoxService --pidfile /var/run/vboxadd-service.sh
        root 1013 0.0 1.6 562416 16444 ? Ssl 02:50 0:03 /usr/bin/python -Es /usr/sbin/tuned -l -P
        root 1015 0.0 0.4 105996 4108 ? Ss 02:50 0:00 /usr/sbin/sshd -D
        root 20191 0.0 0.5 152116 5576 ? Ss 10:06 0:00 _ sshd: vagrant [priv]
        vagrant 20193 0.0 0.2 152304 2872 ? S 10:06 0:00 _ sshd: vagrant@pts/0
        vagrant 20194 0.0 0.2 115964 2644 pts/0 Ss 10:06 0:00 _ -bash
        root 20232 0.0 0.2 201844 2956 pts/0 S 10:06 0:00 _ sudo -Es
        root 20233 0.0 0.2 116208 2964 pts/0 S 10:06 0:00 _ /bin/bash
        root 20510 0.0 0.1 151240 1932 pts/0 R+ 11:01 0:00 _ ps auxf
        root 1115 0.0 0.2 91628 2192 ? Ss 02:50 0:00 /usr/libexec/postfix/master -w
        postfix 1117 0.0 0.3 91800 4048 ? S 02:50 0:00 _ qmgr -l -t unix -u
        postfix 20149 0.0 0.3 91776 4048 ? S 09:39 0:00 _ pickup -l -t unix -u
        ...


        Additionally if you just want to view the list of PID + PGID you can use ps with these switches like so:



        $ ps x -o "%p %r %c"
        PID PGID COMMAND
        1 1 systemd
        2 0 kthreadd
        3 0 ksoftirqd/0
        5 0 kworker/0:0H
        7 0 migration/0
        8 0 rcu_bh
        ...
        ...
        591 591 rngd
        594 594 systemd-logind
        596 596 smartd
        597 597 rsyslogd
        600 600 acpid
        616 616 abrtd
        617 617 abrt-watch-log
        630 630 atd
        637 637 agetty
        983 981 VBoxService
        1013 1013 tuned
        1015 1015 sshd
        1115 1115 master
        2426 2426 NetworkManager
        2439 2439 dhclient
        3123 3123 firewalld
        3828 0 kworker/u2:1






        share|improve this answer













        share|improve this answer



        share|improve this answer











        answered Jul 5 at 15:05









        slm♦

        233k65479651




        233k65479651






















             

            draft saved


            draft discarded


























             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f453602%2fhow-to-view-the-names-all-child-processes-spawned-by-a-program%23new-answer', 'question_page');

            );

            Post as a guest













































































            Popular posts from this blog

            Peggy Mitchell

            Palaiologos

            The Forum (Inglewood, California)