From: Rainer Weikusat on
Sasha <agalkin(a)audible.com> writes:
> Is there way on UNIX to wait for particular process (not child
> process) identified by pid? I know how to wait for a child process but
> is there way to wait for not child process?

Yes, when using the debugging interface. Details are system
specific. The traditional facility would be the 'ptrace' call.
From: Sasha on
On Apr 7, 11:04 pm, Ian Collins <ian-n...(a)hotmail.com> wrote:
> On 04/ 8/10 02:28 PM, Sasha wrote:
>
>
>
> > On Apr 7, 8:01 pm, Ian Collins<ian-n...(a)hotmail.com>  wrote:
> >> On 04/ 8/10 10:45 AM, Sasha wrote:
>
> >>> Is there way on UNIX to wait for particular process (not child
> >>> process) identified by pid? I know how to wait for a child process but
> >>> is there way to wait for not child process?
>
> >> You can't.
>
> >> The closest you can get would be to poll the process with
>
> >> kill( pid, 0 );
>
> >> assuming the pid isn't reused too quickly.
>
> >> Why would you want to?
>
> [best not to quote sigs]
>
>
>
> > I need to watch a particular already running process until it exists.
> > On Windows I would call OpenPorocess to get the process handle and
> > then use WaitForSingleObject to wait on the handle. I wonder why UNIX
> > does not have something similar?
>
> Probably because it's seldom needed.  The process that's normally
> interested in waiting for another to exit is the parent processes.  On
> that basis, you could spawn the process of interest and have to parent
> signal you when the child completes.
>
> What exactly are you trying to achieve?  There's probably a better way
> if you provide some more information.
>
> --
> Ian Collins- Hide quoted text -
>
> - Show quoted text -

I need to wait for already running process to track when it exits. I
know how to do this for the child process spawned by the watcher
process, I need now to do the same for the process already running.
From: Rainer Weikusat on
Sasha <agalkin(a)audible.com> writes:

[...]

> I need to wait for already running process to track when it exits. I
> know how to do this for the child process spawned by the watcher
> process, I need now to do the same for the process already running.

"man ptrace"
From: Casper H.S. Dik on
Sasha <agalkin(a)audible.com> writes:

>I need to wait for already running process to track when it exits. I
>know how to do this for the child process spawned by the watcher
>process, I need now to do the same for the process already running.

Solaris has a utility called "pwait"; it does what you want.

If you don't have pwait, you'll need to make your own using
either ptrace() or whatever functionality your kernel has to
catch an unrelated process. It is possible that "strace()"
allows you to do this (e.g., by only tracing the "exit" call
so you don't incur a large penalty on the process)

Casper
--
Expressed in this posting are my opinions. They are in no way related
to opinions held by my employer, Sun Microsystems.
Statements on Sun products included here are not gospel and may
be fiction rather than truth.
From: David Schwartz on
On Apr 8, 7:57 am, Sasha <agal...(a)audible.com> wrote:

> I need to wait for already running process to track when it exits. I
> know how to do this for the child process spawned by the watcher
> process, I need now to do the same for the process already running.

What's your outer problem? Why do you care whether this particular
process is still running or not?

There's a strong chance there's a good solution to your problem, but
you're still telling us how you think it should be solved. We need to
know what the actual problem is.

DS