Of course, there are some hacks that allow you to do things that look a bit like it (pipes, expect
etc.). But the main answer is: no.
A simplistic view of what happens normally: When you start a process like ls
, the shell does a fork
and exec
. That means that the new process is a child of the current process. The child will execute with it's own PID. As an example:
pstree -p $$
bash(7695)─┬─pstree(13922)
└─sleep(13899)
Here you see my shell (PID=7695) and a sleep
that is executed by the shell. You see that the PID is different. It always is. It can never have the same PID as another process.
So, the next question is whether you can make another process (your PID=100 shell) fork&exec an ls
as a child (so with another PID). The answer is normally no, unless you make some provisions for that (like using a fifo and executing lines that are dumped in the fifo. Executing everything that is dumped in a fifo has some security, eh, lets call them challenges.
My advice: don't go there. Re-evaluate the reasons for doing this.