3

I am looking for a linux command (like ls, time or anything similar) that spawns multiple processes. Anything which is to be run from a command line and not a shell script.

The reason is I want to see parent-child relationship on the htop and with different Process IDs.

Thanks

3
  • 4
    It might be easier to write a program than to use an existing command. After all, commands exist to do something, and you might not want that something to be done. You could easily write a program that spawns processes that do something like compute the first N primes, taking up processor cycles but having no other effect on your system.
    – jamesqf
    Feb 1, 2019 at 18:05
  • Would dig do?
    – kasperd
    Feb 2, 2019 at 14:18
  • @jamesqf Thanks! I actually wanted to avoid writing a Multithread code myself. But, your argument on "commands do something which I don't want" gives me enough motivation to write one. Feb 3, 2019 at 12:25

2 Answers 2

14

The & command separator will do this for you. Use it carefully and wisely, but here is a simple way to see process relationships:

$ sleep 5 & pstree -p $$
[1] 13369
bash(13337)─┬─pstree(13370)
            └─sleep(13369)

The [1] 13369 shows that sleep (which has PID 13369), has been put into the background as Job #1. $$ returns to the shell the PID of itself, so we feed that into pstree to show the process tree with a root of our shell's PID, to show all child processes.

1
  • In fact, I want to avoid shell in the picture altogether. But, the hack is nice! Feb 3, 2019 at 12:29
9

If you don't want to have any shells in the mix, you can simply use one of the "wrapper" programs that spawn another program to do something with it:

  • /bin/time sleep 60
  • watch sleep 1 (this one will keep respawning sleep)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.