From: Jon LaBadie on 9 Jan 2010 09:05 Mark Hobley wrote: > Moody <nasir.mahmood(a)gmail.com> wrote: >> `man sh ` >> >> >> (list) >> Execute list in a sub-shell. >> >> >> I've already tried like below >> >> $ (echo $$) >> 17317 >> $ echo $$ >> 17317 >> $ >> >> >> both shells have same pid, which I understand as same shell and not a >> subshell.. > > Yeah. I encountered a similar thing last year. The documentation in the manual > page may not be correct. It depends on the shell: > > Barry Margolin <barmar(a)alum.mit.edu> wrote: >> Parentheses are standard shell syntax, they cause the command to be run >> in a subshell. > > Hmmm, I just tried this with a script as follows: > > #!/bin/sh > echo "`ps -fL`" > echo > echo "`(ps -fL)`" > echo > > UID PID PPID LWP C NLWP STIME TTY TIME CMD > mark 1071 1070 1071 0 1 Apr11 pts/2 00:00:00 sh > mark 2773 1071 2773 0 1 06:38 pts/2 00:00:00 sh test > mark 2774 2773 2774 0 1 06:38 pts/2 00:00:00 ps -fL > > UID PID PPID LWP C NLWP STIME TTY TIME CMD > mark 1071 1070 1071 0 1 Apr11 pts/2 00:00:00 sh > mark 2773 1071 2773 0 1 06:38 pts/2 00:00:00 sh test > mark 2775 2773 2775 0 1 06:38 pts/2 00:00:00 ps -fL > > I would have expected an extra shell in the second set and the > second ps to have a different parent, because it runs from a subshell. > > I try various shells: > In those instances where no additional process was noted, the shell may have started a new shell in a new process but then, recognizing that only one command was to be executed, chose to exec the ps command in the same process rather than running it in a separate process.
From: Seebs on 9 Jan 2010 23:53 On 2010-01-08, Moody <nasir.mahmood(a)gmail.com> wrote: > both shells have same pid, which I understand as same shell and not a > subshell.. No, both shells have same $$. Which is the pid of the shell, normally, or the parent shell, for a subshell. :) -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam(a)seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!
From: Mark Hobley on 10 Jan 2010 04:08 Jon LaBadie <jlabadie(a)axcxm.org> wrote: > In those instances where no additional process was noted, the shell > may have started a new shell in a new process but then, recognizing that > only one command was to be executed, chose to exec the ps command in the > same process rather than running it in a separate process. I don't know. I wonder if there is some sort of trick that we can do to fool the subshell into revealing itself. Mark. -- Mark Hobley Linux User: #370818 http://markhobley.yi.org/
From: Sven Mascheck on 10 Jan 2010 07:18 Sven Mascheck wrote: > A subshell is "only" a new environment, which has a relationship > like a child. But it's not a new child process. ....oh, not necessarily: some shells do implement this (I was confused, and didn't get some other postings right) Mark Hobley wrote: > I wonder if there is some sort of trick that we can do to fool > the subshell into revealing itself. In the process list, or rather in the subshell itself? -- [going on superseding, let alone the broken references]
From: Mark Hobley on 10 Jan 2010 11:08 Sven Mascheck <mascheck(a)email.invalid> wrote: > In the process list, or rather in the subshell itself? Well. I would have first expected this in the process list. However, if the subshell is actually the same process as the parent, I am wondering if it is possible to have both a shell and subshell running interactively. It would be interesting to see the two interactive sessions but only one process for them on the process list. Or maybe the exec theory is true, in which case we do get a second shell, but that gets replaced. Maybe we could trap the creation of the second shell before the replacement takes place. (Obviously this is all just academic, but it would be interesting to see what is actually happening, and whether or not one shell differs from another.) I suppose we could do a system trace, or worse ... look at the code :) to examine this. Mark. -- Mark Hobley Linux User: #370818 http://markhobley.yi.org/
First
|
Prev
|
Next
|
Last
Pages: 1 2 3 4 5 Prev: select last field of line (cut/sed/awk etc) Next: m to n or just n |