Bookmarks

Yahoo Gmail Google Facebook Delicious Twitter Reddit Stumpleupon Myspace Digg

Search queries

wwwxxx0CM, wwwxxx0CM, wwwxxx0CM, vba and cddb, www.xxx.con, wwwxxxcon, w.w.w.XXXCON, wwwxxx.b, wwwxxx KSH, wwwxxx KSH

Links

XODOX
Impressum

#1: get current PID in ksh

Posted on 2005-09-07 11:20:37 by mark

Here's a variation on an age old topic. I'm having trouble, in ksh, of
getting my own PID. Have tried $$, but unfortunately.. this doesn't
work because..

Try this:

silly.ksh is:

#!/bin/ksh
.. ./silly2.ksh &

silly2.ksh is:
#!/bin/ksh
print $$

now, when you run ./silly.ksh, printed is the PID of silly.ksh NOT
silly2.ksh which is what I want. Actually, silly2.ksh appears in a
process listing as silly.ksh which is the desired behaviour but because
of the &, $$ when printed, isn't actually a running process of any
form.

Any thoughts / suggestions?

Cheers,

Mark

Report this message

#2: Re: get current PID in ksh

Posted on 2005-09-07 17:43:27 by Greg Beeker

mark@gowans.org wrote:
> Here's a variation on an age old topic. I'm having trouble, in ksh, of
> getting my own PID. Have tried $$, but unfortunately.. this doesn't
> work because..
>
> Try this:
>
> silly.ksh is:
>
> #!/bin/ksh
> . ./silly2.ksh &
>
> silly2.ksh is:
> #!/bin/ksh
> print $$
>
> now, when you run ./silly.ksh, printed is the PID of silly.ksh NOT
> silly2.ksh which is what I want. Actually, silly2.ksh appears in a
> process listing as silly.ksh which is the desired behaviour but because
> of the &, $$ when printed, isn't actually a running process of any
> form.
>
> Any thoughts / suggestions?

Try this:
$ more myppid.ksh
(echo "my pid "$$; ps -fp $$ | tail -1 | awk '{print "my ppid ",$3}' )
sleep 999

Tested on AIX 51

Report this message

#3: Re: get current PID in ksh

Posted on 2005-09-07 18:55:41 by cfajohnson

On 2005-09-07, mark@gowans.org wrote:
> Here's a variation on an age old topic. I'm having trouble, in ksh, of
> getting my own PID. Have tried $$, but unfortunately.. this doesn't
> work because..
>
> Try this:
>
> silly.ksh is:
>
> #!/bin/ksh
> . ./silly2.ksh &
>
> silly2.ksh is:
> #!/bin/ksh
> print $$
>
> now, when you run ./silly.ksh, printed is the PID of silly.ksh NOT
> silly2.ksh which is what I want. Actually, silly2.ksh appears in a
> process listing as silly.ksh which is the desired behaviour but because
> of the &, $$ when printed, isn't actually a running process of any
> form.

Using both ',' and '&' is meaningless; the behaviour is undefined.

If you want to run the script in the current shell, leave out '&';
if you want to run it in the background, leave out '.'.

--
Chris F.A. Johnson <http://cfaj.freeshell.org>
============================================================ ======
Shell Scripting Recipes: A Problem-Solution Approach, 2005, Apress
<http://www.torfree.net/~chris/books/cfaj/ssr.html>

Report this message

#4: Re: get current PID in ksh

Posted on 2005-09-08 11:24:12 by ravindra.s.agarwal

If you want the PID of the background process, use the following in
silly.sh script:

#!/bin/ksh
.. ./silly2.ksh &
echo $!

Report this message

#5: Re: get current PID in ksh

Posted on 2005-09-08 15:11:10 by Geoff Clare

"Chris F.A. Johnson" <cfajohnson@gmail.com> wrote, on Wed, 07 Sep 2005:

>> #!/bin/ksh
>> . ./silly2.ksh &
>>
>> silly2.ksh is:
>> #!/bin/ksh
>> print $$
[snip]
>
> Using both ',' and '&' is meaningless; the behaviour is undefined.

I don't think the behaviour is undefined.

POSIX says "If a command is terminated by the control operator
ampersand ( '&' ), the shell shall execute the command asynchronously
in a subshell."

So

. ./silly2.ksh &

is equivalent to:

(
. ./silly2.ksh
) &

which in turn is equivalent to:

(
#!/bin/ksh
print $$
) &

--
Geoff Clare <netnews@gclare.org.uk>

Report this message

#6: Re: get current PID in ksh

Posted on 2005-09-08 15:55:32 by cfajohnson

On 2005-09-08, Geoff Clare wrote:
> "Chris F.A. Johnson" <cfajohnson@gmail.com> wrote, on Wed, 07 Sep 2005:
>
>>> #!/bin/ksh
>>> . ./silly2.ksh &
>>>
>>> silly2.ksh is:
>>> #!/bin/ksh
>>> print $$
> [snip]
>>
>> Using both ',' and '&' is meaningless; the behaviour is undefined.
>
> I don't think the behaviour is undefined.

OK; just meaningless.

> POSIX says "If a command is terminated by the control operator
> ampersand ( '&' ), the shell shall execute the command asynchronously
> in a subshell."

How did the word asynchronously come to mean the opposite of its
meaning in English? It means the opposite of synchronously, which
means "at the same time".

From The Collaborative International Dictionary of English v.0.44 [gcide]:

Asynchronous \A*syn"chro*nous\, a. [Gr. ? not + synchronous.]
Not simultaneous; not concurrent in time; -- opposed to
{synchronous}.


From The Free On-line Dictionary of Computing (09 FEB 02) [foldoc]:

asynchronous
....
1. <operating system> A {process} in a {multitasking} system
whose execution can proceed independently, "in the
{background}". Other processes may be started before the
asynchronous process has finished.


--
Chris F.A. Johnson <http://cfaj.freeshell.org>
============================================================ ======
Shell Scripting Recipes: A Problem-Solution Approach, 2005, Apress
<http://www.torfree.net/~chris/books/cfaj/ssr.html>

Report this message

#7: Re: get current PID in ksh

Posted on 2005-09-08 17:12:02 by joe

"Chris F.A. Johnson" <cfajohnson@gmail.com> writes:

> On 2005-09-08, Geoff Clare wrote:
> > "Chris F.A. Johnson" <cfajohnson@gmail.com> wrote, on Wed, 07 Sep 2005:

> > POSIX says "If a command is terminated by the control operator
> > ampersand ( '&' ), the shell shall execute the command
> > asynchronously in a subshell."
>
> How did the word asynchronously come to mean the opposite of its
> meaning in English? It means the opposite of synchronously, which
> means "at the same time".

In this context asynchronous generally means "can't be predicted" or
"can be interrupted" or something of the kind. Synchronous means
"predictable", "continuous", etc.

Joe
--
I never veer to starboard 'cuz I never sail at all
- The Pirates Who Don't do Anything

Report this message

#8: Re: get current PID in ksh

Posted on 2005-09-08 18:44:15 by Enrique Perez-Terron

On Thu, 08 Sep 2005 15:55:32 +0200, Chris F.A. Johnson
<cfajohnson@gmail.com> wrote:
> How did the word asynchronously come to mean the opposite of its
> meaning in English? It means the opposite of synchronously, which
> means "at the same time".

Good question!

However, in computing, it seems that "synchronous" has come to mean "bound
into the timeline, in strictly ordered fashion", while "asynchronous"
means "not synchronous" or "at some independent time" or "having an
independent timeline"

Regards
Enrique

Report this message

#9: Re: get current PID in ksh

Posted on 2005-09-08 18:59:57 by cfajohnson

On 2005-09-08, Enrique Perez-Terron wrote:
> On Thu, 08 Sep 2005 15:55:32 +0200, Chris F.A. Johnson
><cfajohnson@gmail.com> wrote:
>> How did the word asynchronously come to mean the opposite of its
>> meaning in English? It means the opposite of synchronously, which
>> means "at the same time".
>
> Good question!
>
> However, in computing, it seems that "synchronous" has come to mean "bound
> into the timeline, in strictly ordered fashion", while "asynchronous"
> means "not synchronous" or "at some independent time" or "having an
> independent timeline"

Because of the conflicting meanings, I never use "synchronous" or
"asynchronous". I say that commands run consecutively, except for
background tasks which run concurrently.

--
Chris F.A. Johnson <http://cfaj.freeshell.org>
============================================================ ======
Shell Scripting Recipes: A Problem-Solution Approach, 2005, Apress
<http://www.torfree.net/~chris/books/cfaj/ssr.html>

Report this message

#10: Re: get current PID in ksh

Posted on 2005-09-08 20:28:47 by joe

"Chris F.A. Johnson" <cfajohnson@gmail.com> writes:

> On 2005-09-08, Enrique Perez-Terron wrote:
> > On Thu, 08 Sep 2005 15:55:32 +0200, Chris F.A. Johnson
> ><cfajohnson@gmail.com> wrote:
> >> How did the word asynchronously come to mean the opposite of its
> >> meaning in English? It means the opposite of synchronously, which
> >> means "at the same time".
> >
> > Good question!
> >
> > However, in computing, it seems that "synchronous" has come to
> > mean "bound into the timeline, in strictly ordered fashion", while
> > "asynchronous" means "not synchronous" or "at some independent
> > time" or "having an independent timeline"
>
> Because of the conflicting meanings, I never use "synchronous" or
> "asynchronous". I say that commands run consecutively, except for
> background tasks which run concurrently.

Which term do you use for callback functions in a multithreaded
program? Not really a shell question but I'm curious.

Joe
--
I never veer to starboard 'cuz I never sail at all
- The Pirates Who Don't do Anything

Report this message

#11: Re: get current PID in ksh

Posted on 2005-09-08 20:33:58 by cfajohnson

On 2005-09-08, joe@invalid.address wrote:
> "Chris F.A. Johnson" <cfajohnson@gmail.com> writes:
>
>> On 2005-09-08, Enrique Perez-Terron wrote:
>> > On Thu, 08 Sep 2005 15:55:32 +0200, Chris F.A. Johnson
>> ><cfajohnson@gmail.com> wrote:
>> >> How did the word asynchronously come to mean the opposite of its
>> >> meaning in English? It means the opposite of synchronously, which
>> >> means "at the same time".
>> >
>> > Good question!
>> >
>> > However, in computing, it seems that "synchronous" has come to
>> > mean "bound into the timeline, in strictly ordered fashion", while
>> > "asynchronous" means "not synchronous" or "at some independent
>> > time" or "having an independent timeline"
>>
>> Because of the conflicting meanings, I never use "synchronous" or
>> "asynchronous". I say that commands run consecutively, except for
>> background tasks which run concurrently.
>
> Which term do you use for callback functions in a multithreaded
> program? Not really a shell question but I'm curious.

I don't.

Do they run consecutively or concurrently?

--
Chris F.A. Johnson <http://cfaj.freeshell.org>
============================================================ ======
Shell Scripting Recipes: A Problem-Solution Approach, 2005, Apress
<http://www.torfree.net/~chris/books/cfaj/ssr.html>

Report this message

#12: Re: get current PID in ksh

Posted on 2005-09-08 23:13:10 by joe

"Chris F.A. Johnson" <cfajohnson@gmail.com> writes:

> On 2005-09-08, joe@invalid.address wrote:
> > "Chris F.A. Johnson" <cfajohnson@gmail.com> writes:
> >
> >> On 2005-09-08, Enrique Perez-Terron wrote:
> >> > On Thu, 08 Sep 2005 15:55:32 +0200, Chris F.A. Johnson
> >> ><cfajohnson@gmail.com> wrote:
> >> >> How did the word asynchronously come to mean the opposite
> >> >> of its meaning in English? It means the opposite of
> >> >> synchronously, which means "at the same time".
> >> >
> >> > Good question!
> >> >
> >> > However, in computing, it seems that "synchronous" has come to
> >> > mean "bound into the timeline, in strictly ordered fashion",
> >> > while "asynchronous" means "not synchronous" or "at some
> >> > independent time" or "having an independent timeline"
> >>
> >> Because of the conflicting meanings, I never use
> >> "synchronous" or "asynchronous". I say that commands run
> >> consecutively, except for background tasks which run
> >> concurrently.
> >
> > Which term do you use for callback functions in a multithreaded
> > program? Not really a shell question but I'm curious.
>
> I don't.
>
> Do they run consecutively or concurrently?

That's the point.

Joe
--
I never veer to starboard 'cuz I never sail at all
- The Pirates Who Don't do Anything

Report this message

#13: Re: get current PID in ksh

Posted on 2005-09-08 23:41:07 by Bruce Barnett

"Enrique Perez-Terron" <enrio@online.no> writes:

> However, in computing, it seems that "synchronous" has come to mean
> "bound into the timeline, in strictly ordered fashion", while
> "asynchronous" means "not synchronous" or "at some independent time"
> or "having an independent timeline"

Yup, I think some other operating systems used to have both synchronous and
asynchronous I/O system calls. (like VMS?)

Asynchronous calls meant you started them up, and then continued with
your program while the I/O was being processed, But you have to get
the results later with a second call.

Early unix systems didn't have async I/O AFAIK.

--
Sending unsolicited commercial e-mail to this account incurs a fee of
$500 per message, and acknowledges the legality of this contract.

Report this message

#14: Re: get current PID in ksh

Posted on 2005-09-17 20:05:31 by bonomi

In article <kfs5v2-04t.ln1@rogers.com>,
Chris F.A. Johnson <cfajohnson@gmail.com> wrote:
>On 2005-09-08, Geoff Clare wrote:
>> "Chris F.A. Johnson" <cfajohnson@gmail.com> wrote, on Wed, 07 Sep 2005:
>>
>>>> #!/bin/ksh
>>>> . ./silly2.ksh &
>>>>
>>>> silly2.ksh is:
>>>> #!/bin/ksh
>>>> print $$
>> [snip]
>>>
>>> Using both ',' and '&' is meaningless; the behaviour is undefined.
>>
>> I don't think the behaviour is undefined.
>
> OK; just meaningless.
>
>> POSIX says "If a command is terminated by the control operator
>> ampersand ( '&' ), the shell shall execute the command asynchronously
>> in a subshell."
>
> How did the word asynchronously come to mean the opposite of its
> meaning in English? It means the opposite of synchronously, which
> means "at the same time".

WRONG meaning for 'synchronously'. :)

>
>From The Collaborative International Dictionary of English v.0.44 [gcide]:
>
> Asynchronous \A*syn"chro*nous\, a. [Gr. ? not + synchronous.]
> Not simultaneous; not concurrent in time; -- opposed to
> {synchronous}.

*bad* definition.
>
>
>From The Free On-line Dictionary of Computing (09 FEB 02) [foldoc]:
>
> asynchronous
> ....
> 1. <operating system> A {process} in a {multitasking} system
> whose execution can proceed independently, "in the
> {background}". Other processes may be started before the
> asynchronous process has finished.
>

Synchronous -- (see synchronized) -- happens with a fixed timing relationship
to other events. Can mean that both things _start_ at the same point in
time, can mean that the 2nd thing can start only when the first one _ends_.

Asynchronous -- happens _without_regard_ to the timing of any other events.


In the UNIX world, 'foreground' tasks are limited to synchronous operation.
the 'next' task has to wait for the previous one to complete before starting.
'Background' tasks, on the other hand, proceed independantly of whatever is
going on in the 'forground', *or* of what any other background task is doing.
hence they are said to execute asynchronously -- they do their thing 'without
regard' for the timing of any other events.

all clear now? <grin>


>
>--
> Chris F.A. Johnson <http://cfaj.freeshell.org>
> ============================================================ ======
> Shell Scripting Recipes: A Problem-Solution Approach, 2005, Apress
> <http://www.torfree.net/~chris/books/cfaj/ssr.html>

Report this message

#15: Re: get current PID in ksh

Posted on 2005-09-17 20:35:03 by cfajohnson

On 2005-09-17, Robert Bonomi wrote:
> In article <kfs5v2-04t.ln1@rogers.com>,
> Chris F.A. Johnson <cfajohnson@gmail.com> wrote:
>>On 2005-09-08, Geoff Clare wrote:
>>> "Chris F.A. Johnson" <cfajohnson@gmail.com> wrote, on Wed, 07 Sep 2005:
>>>
>>>>> #!/bin/ksh
>>>>> . ./silly2.ksh &
>>>>>
>>>>> silly2.ksh is:
>>>>> #!/bin/ksh
>>>>> print $$
>>> [snip]
>>>>
>>>> Using both ',' and '&' is meaningless; the behaviour is undefined.
>>>
>>> I don't think the behaviour is undefined.
>>
>> OK; just meaningless.
>>
>>> POSIX says "If a command is terminated by the control operator
>>> ampersand ( '&' ), the shell shall execute the command asynchronously
>>> in a subshell."
>>
>> How did the word asynchronously come to mean the opposite of its
>> meaning in English? It means the opposite of synchronously, which
>> means "at the same time".
>
> WRONG meaning for 'synchronously'. :)

Wrong only for the context, not for the standard English meaning
of the word.

>>From The Collaborative International Dictionary of English v.0.44 [gcide]:
>>
>> Asynchronous \A*syn"chro*nous\, a. [Gr. ? not + synchronous.]
>> Not simultaneous; not concurrent in time; -- opposed to
>> {synchronous}.
>
> *bad* definition.

Good (i.e., English) definition.

>>From The Free On-line Dictionary of Computing (09 FEB 02) [foldoc]:
>>
>> asynchronous
>> ....
>> 1. <operating system> A {process} in a {multitasking} system
>> whose execution can proceed independently, "in the
>> {background}". Other processes may be started before the
>> asynchronous process has finished.
>>
>
> Synchronous -- (see synchronized) -- happens with a fixed timing relationship
> to other events. Can mean that both things _start_ at the same point in
> time, can mean that the 2nd thing can start only when the first one _ends_.
>
> Asynchronous -- happens _without_regard_ to the timing of any other events.

Whis is computerese, not English.

> In the UNIX world, 'foreground' tasks are limited to synchronous
>>operation.

Not according to the English meaning of the word.

> the 'next' task has to wait for the previous one to complete before starting.
> 'Background' tasks, on the other hand, proceed independantly of whatever is
> going on in the 'forground', *or* of what any other background task is doing.
> hence they are said to execute asynchronously -- they do their thing 'without
> regard' for the timing of any other events.
>
> all clear now? <grin>

Yes. The word synchronous has been adopted by the computer culture
when it meant synchronized.

--
Chris F.A. Johnson <http://cfaj.freeshell.org>
============================================================ ======
Shell Scripting Recipes: A Problem-Solution Approach, 2005, Apress
<http://www.torfree.net/~chris/books/cfaj/ssr.html>

Report this message

#16: Re: get current PID in ksh

Posted on 2005-09-17 21:29:41 by bonomi

In article <n74uv2-kk2.ln1@rogers.com>,
Chris F.A. Johnson <cfajohnson@gmail.com> wrote:
>On 2005-09-17, Robert Bonomi wrote:
>> In article <kfs5v2-04t.ln1@rogers.com>,
>> Chris F.A. Johnson <cfajohnson@gmail.com> wrote:
>>>On 2005-09-08, Geoff Clare wrote:
>>>> "Chris F.A. Johnson" <cfajohnson@gmail.com> wrote, on Wed, 07 Sep 2005:
>>>>
>>>>>> #!/bin/ksh
>>>>>> . ./silly2.ksh &
>>>>>>
>>>>>> silly2.ksh is:
>>>>>> #!/bin/ksh
>>>>>> print $$
>>>> [snip]
>>>>>
>>>>> Using both ',' and '&' is meaningless; the behaviour is undefined.
>>>>
>>>> I don't think the behaviour is undefined.
>>>
>>> OK; just meaningless.
>>>
>>>> POSIX says "If a command is terminated by the control operator
>>>> ampersand ( '&' ), the shell shall execute the command asynchronously
>>>> in a subshell."
>>>
>>> How did the word asynchronously come to mean the opposite of its
>>> meaning in English? It means the opposite of synchronously, which
>>> means "at the same time".
>>
>> WRONG meaning for 'synchronously'. :)
>
> Wrong only for the context, not for the standard English meaning
> of the word.

BZZZT!

Synchronous:
1) occurring at the same time.
2) moving or operating at the same rate
3a) having identical periods
3b) having identical period and phase.

In the computer world, "meaning "2 of the word is the generally applicable one.

And 'asynchronous'

>
>>>From The Collaborative International Dictionary of English v.0.44 [gcide]:
>>>
>>> Asynchronous \A*syn"chro*nous\, a. [Gr. ? not + synchronous.]
>>> Not simultaneous; not concurrent in time; -- opposed to
>>> {synchronous}.
>>
>> *bad* definition.
>
> Good (i.e., English) definition.

FALSE TO FACT.

"simultaneous; concurrent in time" is the dictionary definition of
'synchronize', *not* 'synchronous'>

Thus, it is an ERRONEOUS definition -- as it implies that 'asynchronous' forces
one particular meaning, of *several*, on the root word. (synchronous)

>>>From The Free On-line Dictionary of Computing (09 FEB 02) [foldoc]:
>>>
>>> asynchronous
>>> ....
>>> 1. <operating system> A {process} in a {multitasking} system
>>> whose execution can proceed independently, "in the
>>> {background}". Other processes may be started before the
>>> asynchronous process has finished.
>>>
>>
>> Synchronous -- (see synchronized) -- happens with a fixed timing relationship
>> to other events. Can mean that both things _start_ at the same point in
>> time, can mean that the 2nd thing can start only when the first one _ends_.
>>
>> Asynchronous -- happens _without_regard_ to the timing of any other events.
>
> Whis is computerese, not English.

If you say so. Of course the words were used that way as far back as the
1920s (probably further, but the references I have on hand are from that era),
in describing industrial process-control management -- where the 'events' were
being executed *manually*.

>
>> In the UNIX world, 'foreground' tasks are limited to synchronous
>>>operation.
>
> Not according to the English meaning of the word.

Yes, according to _one_of_ the long-accepted English meanings.
Synchronous does *NOT* necessarily imply simultaneous/parallel operation.

See 'synchronous motor' for one example that predates computers.
Again, references for that are available that go back to the 1930s, and before.

>> the 'next' task has to wait for the previous one to complete before starting.
>> 'Background' tasks, on the other hand, proceed independantly of whatever is
>> going on in the 'forground', *or* of what any other background task is doing.
>> hence they are said to execute asynchronously -- they do their thing 'without
>> regard' for the timing of any other events.
>>
>> all clear now? <grin>
>
> Yes. The word synchronous has been adopted by the computer culture
> when it meant synchronized.

"not exactly". There are fine points of difference in the usage of the two
words. When you have a 'clock' for a timing reference, then 'synchronized'
means that events occur at a time relative to a *SPECIFIC* clock-tick --
whether or not they occur simultaneously with each other. "Synchronous"
means that each event occurs at a time relative to "an arbitrary" clock-tick,
and *NOT*NECESSARILY* involving the same 'reference' tick for each event.

"Common usage" English has gotten 'sloppy' about the fine shades of meaning,
leading to confusion.

The technical community has utilized the proper distinction, long before
computers came on the scene.

"Just because" two processes are occurring CONCURRENTLY, that does not mean
that they are necessarily synchronous nor necessarily synchronized.

'Background' tasks on a computer are *not* synchronous, nor synchronized,
with each other, or with any foreground tasks. they do not *start* at
the same time, they do not _finish_ at the same time, they do not necessarily,
move at the same rate, etc.

Lacking that begin/end synchronization, as well as lacking any synchronization
at any intermediate points in processing the task, *and* considering that said
background tasks usually operate at a reduced scheduling priority relative to
foreground tasks (so they are not even on the same 'clock', as it were) it
_is_ fair, reasonable -- and entirely accurate -- to describe background
tasks as operating 'asynchronously' from those in the foreground.

The traffic light on the corner, and the water sprinkler in my front yard
are both operating at the same time ("concurrently"). By your definition,
because of that, they are operating synchronously.

Report this message