I can make a dummy process that will hang forever and get its PID with:

bash -c 'echo $$; read'

I'd like a multi-threaded alternative to this one-liner which creates 2+ threads, prints the thread ids of each thread, then every thread blocks. Usage would look something like:

$ launch-multithread

Is this possible with common Unix utilities?

For the curious, I'd like to do this because I'm playing with cgroups and want to avoid messing with any processes doing something I care about.

  • Hmm this works but I hate having an inline python program: sh -c 'python3 -c "import threading, time; threading.Thread(target=lambda: time.sleep(50)).start(); time.sleep(50)" & sleep 1; ls /proc/$!/task;'
    – jrpear
    Mar 15, 2022 at 0:36

1 Answer 1


Here is a very simple way to accomplish your goal.

#!/usr/bin/env bash

sh -c "sleep 3600" &
echo $!
sh -c "sleep 3600" &
echo $!

Using sleep 3600 will keep your process alive for 1 hour - adjust as needed.

  • 1
    That launches multiple processes, none of which are multi-threaded. Mar 14, 2022 at 22:34
  • Yes, these are processes. On Linux, process IDs and thread IDs are allocated from the same numbering space, so I thought this would suffice.
    – clownbaby
    Mar 14, 2022 at 22:51
  • Yeah this would work in many situations. However, I need a multi-threaded single process.
    – jrpear
    Mar 14, 2022 at 23:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .