[cs631apue] About login sh process

Jan Schaumann jschauma at stevens.edu
Fri Dec 13 21:55:29 EST 2019


Yuxi Wang <ywang286 at stevens.edu> wrote:
> 
>   1.  For the long pipeline example, I tried to only run the first command separately, and I got a result like this:
> 
> apue$ ( ps -o pid,ppid,pgid,sid,comm; sleep 1; )
> 
> PID PPID PGID SID COMMAND
> 973  724  973 973 -sh
> 509  973  509 973 -sh
> 922  509  509 973 ps
> 
> My question is in the point 2 above why the result is not like the long pipe example which has 3 -sh?

That is because you have no pipeline here.

Your current shell (PID 973) reads the command you
type, notices that there is no pipeline and thus does
not fork a new process to run a pipeline in.  It will
fork a new process for the command you run (PID
509), but rather than simply exec whatever command you
give, it sees that you requested a subshell, so forks
another process (PID 922), which then runs the ps(1)
command and sleep builtin.

-Jan


More information about the cs631apue mailing list