zsh-workers
 help / color / mirror / code / Atom feed
* problem using $$
@ 2005-05-13 16:55 Rico Schiekel
  2005-05-16  2:10 ` Bart Schaefer
  0 siblings, 1 reply; 2+ messages in thread
From: Rico Schiekel @ 2005-05-13 16:55 UTC (permalink / raw)
  To: zsh-workers

[-- Attachment #1: Type: text/plain, Size: 1495 bytes --]

hi,

this little script shows a (for me) strange behavior.
,----
| #!/bin/zsh
| #  test.zsh
|
| mp=$$
|
| echo "pid=$mp"
| ps aux | grep " $mp "
| echo "----"
| ps aux | grep "start.osd" | grep -v "grep" | grep -v " $mp "
`----

calling the script often in series, i sometimes got this:
,----
|  [fire@crow] (8028) 2005-05-13 18:33:43
|  [~/bin] -> ./test.zsh
|a pid=4128
|b fire      4128  0.0  0.1  2708 1324 pts/4    R+   18:33   0:00 /bin/zsh ./test.zsh
|  ----
|c fire      4172  0.0  0.1  2708 1332 pts/4    R+   18:33   0:00 /bin/zsh ./test.zsh
|  [fire@crow] (8028) 2005-05-13 18:33:44
|  [~/bin] -> ./test.zsh
|1 pid=4173
|  fire      4173  0.0  0.1  2708 1324 pts/4    S+   18:33   0:00 /bin/zsh ./test.zsh
|  fire      4213  0.0  0.0  1628  504 pts/4    S+   18:33   0:00 grep test.zsh
|  ----
|2 fire      4216  0.0  0.0     0    0 pts/4    R+   18:33   0:00 [test.zsh]
|  [fire@crow] (8028) 2005-05-13 18:33:44
|  [~/bin] ->
`----

- first call:
   why is the process id from the second ps [c] other than the process
   id from the first ps [b] and $$ [a] ?

- second call:
   and what is "[test.zsh]" [2] and why has it got another pid (4216)
   than $$ (4173) [1] ?

am i doing something wrong or is this a bug?

thanx for your help,
rico

-- 
 Rico Schiekel   | Logical Tracking&Tracing International AG
 Dipl. Ing. (FH) | Software Development MDA

 Fight against software patents in EU! www.ffii.org www.nosoftwarepatents.org

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 189 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: problem using $$
  2005-05-13 16:55 problem using $$ Rico Schiekel
@ 2005-05-16  2:10 ` Bart Schaefer
  0 siblings, 0 replies; 2+ messages in thread
From: Bart Schaefer @ 2005-05-16  2:10 UTC (permalink / raw)
  To: Rico Schiekel, zsh-workers

On May 13,  6:55pm, Rico Schiekel wrote:
}
} | ps aux | grep " $mp "
} | ps aux | grep "start.osd" | grep -v "grep" | grep -v " $mp "
} 
} |b fire      4128  0.0  0.1  2708 1324 pts/4    R+   18:33   0:00 /bin/zsh ./test.zsh
} |c fire      4172  0.0  0.1  2708 1332 pts/4    R+   18:33   0:00 /bin/zsh ./test.zsh
} 
} - first call:
}    why is the process id from the second ps [c] other than the process
}    id from the first ps [b] and $$ [a] ?

I think that's because your script is buggy.  The third call to grep in
the [c] case should not have the "-v" option.

After getting rid of the stray "-v", try using "ps alx" rather than "aux".
That will allow you to grep the $mp out of both the PID and PPID columns
and thereby see the parent/child relationship among the shells.

} |2 fire      4216  0.0  0.0     0    0 pts/4    R+   18:33   0:00 [test.zsh]
} 
} - second call:
}    and what is "[test.zsh]" [2]

The ps output has square brackets like that for a child process when the
original process has fork()ed but has not done an execv() in the child.
This means that the "ps" is running soon enough to catch zsh after it
has forked, but before it has finished starting up one of the greps that
appear later in the pipeline.  Vagaries of process scheduling.

}    and why has it got another pid (4216) than $$ (4173) [1] ?

Because your script ran 'grep -v " 4173 "'.


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2005-05-16  2:11 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-05-13 16:55 problem using $$ Rico Schiekel
2005-05-16  2:10 ` Bart Schaefer

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).