Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

inotify and /proc/<pid>

584 views
Skip to first unread message

Joseph Pingenot

unread,
Jul 30, 2007, 10:53:36 PM7/30/07
to linux-...@vger.kernel.org
I was trying to use inotify to watch process changes (especially process
termination) by watching /proc/<pid>.

Sadly, although I could see something reading various files, nothing
was issued when the process I was watching exited and the directory
went away.

Is this intentional, or a bug?

-Joseph
--
tre...@digitasaru.net.///////////////////////////////////////////////
"There is also an entire branch in the physical therapy field dedicated
to the treatment of little-finger injuries caused by excessive Emacs
use." --Linux Weekly News editor (http://lwn.net/Articles/206916/)
///////260 IATL / The University of Iowa / Iowa City, IA 52242///////
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majo...@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

Al Viro

unread,
Jul 30, 2007, 11:17:48 PM7/30/07
to linux-...@vger.kernel.org
On Mon, Jul 30, 2007 at 09:16:16PM -0500, Joseph Pingenot wrote:
> I was trying to use inotify to watch process changes (especially process
> termination) by watching /proc/<pid>.
>
> Sadly, although I could see something reading various files, nothing
> was issued when the process I was watching exited and the directory
> went away.
>
> Is this intentional, or a bug?

It's a bug you intend to introduce in your program... IOW, don't
do that.

Joseph Pingenot

unread,
Jul 30, 2007, 11:26:38 PM7/30/07
to Al Viro, linux-...@vger.kernel.org
From Al Viro on Tuesday, 31 July, 2007:

>On Mon, Jul 30, 2007 at 09:16:16PM -0500, Joseph Pingenot wrote:
>> I was trying to use inotify to watch process changes (especially process
>> termination) by watching /proc/<pid>.
>> Sadly, although I could see something reading various files, nothing
>> was issued when the process I was watching exited and the directory
>> went away.
>> Is this intentional, or a bug?
>It's a bug you intend to introduce in your program... IOW, don't
>do that.

More background, please?

What's the way to check for a process exiting without spinning?

-Joseph

--
tre...@digitasaru.net.///////////////////////////////////////////////
"There is also an entire branch in the physical therapy field dedicated
to the treatment of little-finger injuries caused by excessive Emacs
use." --Linux Weekly News editor (http://lwn.net/Articles/206916/)
///////260 IATL / The University of Iowa / Iowa City, IA 52242///////

Al Viro

unread,
Jul 30, 2007, 11:32:06 PM7/30/07
to linux-...@vger.kernel.org
On Mon, Jul 30, 2007 at 10:25:21PM -0500, Joseph Pingenot wrote:
> >From Al Viro on Tuesday, 31 July, 2007:
> >On Mon, Jul 30, 2007 at 09:16:16PM -0500, Joseph Pingenot wrote:
> >> I was trying to use inotify to watch process changes (especially process
> >> termination) by watching /proc/<pid>.
> >> Sadly, although I could see something reading various files, nothing
> >> was issued when the process I was watching exited and the directory
> >> went away.
> >> Is this intentional, or a bug?
> >It's a bug you intend to introduce in your program... IOW, don't
> >do that.
>
> More background, please?
>
> What's the way to check for a process exiting without spinning?

Depends on what that process is and how it is related to watching
one...

Joseph Pingenot

unread,
Jul 30, 2007, 11:32:28 PM7/30/07
to Al Viro, linux-...@vger.kernel.org
From Joseph Pingenot on Monday, 30 July, 2007:

>From Al Viro on Tuesday, 31 July, 2007:
>>On Mon, Jul 30, 2007 at 09:16:16PM -0500, Joseph Pingenot wrote:
>>> I was trying to use inotify to watch process changes (especially process
>>> termination) by watching /proc/<pid>.
>>> Sadly, although I could see something reading various files, nothing
>>> was issued when the process I was watching exited and the directory
>>> went away.
>>> Is this intentional, or a bug?
>>It's a bug you intend to introduce in your program... IOW, don't
>>do that.
>More background, please?
>What's the way to check for a process exiting without spinning?

I should also specify that the process being waited on is not a
child process-it's just some other process on the system.

Al Viro

unread,
Jul 30, 2007, 11:37:05 PM7/30/07
to linux-...@vger.kernel.org
On Mon, Jul 30, 2007 at 10:31:13PM -0500, Joseph Pingenot wrote:
> >From Joseph Pingenot on Monday, 30 July, 2007:
> >From Al Viro on Tuesday, 31 July, 2007:
> >>On Mon, Jul 30, 2007 at 09:16:16PM -0500, Joseph Pingenot wrote:
> >>> I was trying to use inotify to watch process changes (especially process
> >>> termination) by watching /proc/<pid>.
> >>> Sadly, although I could see something reading various files, nothing
> >>> was issued when the process I was watching exited and the directory
> >>> went away.
> >>> Is this intentional, or a bug?
> >>It's a bug you intend to introduce in your program... IOW, don't
> >>do that.
> >More background, please?
> >What's the way to check for a process exiting without spinning?
>
> I should also specify that the process being waited on is not a
> child process-it's just some other process on the system.

Umm... Any details on intended use? IOW, is that "I want to write
an utility that would wait for given PID to exit, just for the hell
of it" or is there something you are trying to implement using that?

Joseph Pingenot

unread,
Jul 30, 2007, 11:42:03 PM7/30/07
to Al Viro, linux-...@vger.kernel.org
From Al Viro on Tuesday, 31 July, 2007:
>On Mon, Jul 30, 2007 at 10:31:13PM -0500, Joseph Pingenot wrote:
>> >From Joseph Pingenot on Monday, 30 July, 2007:
>> >From Al Viro on Tuesday, 31 July, 2007:
>> >>On Mon, Jul 30, 2007 at 09:16:16PM -0500, Joseph Pingenot wrote:
>> >>> I was trying to use inotify to watch process changes (especially process
>> >>> termination) by watching /proc/<pid>.
>> >>> Sadly, although I could see something reading various files, nothing
>> >>> was issued when the process I was watching exited and the directory
>> >>> went away.
>> >>> Is this intentional, or a bug?
>> >>It's a bug you intend to introduce in your program... IOW, don't
>> >>do that.
>> >More background, please?
>> >What's the way to check for a process exiting without spinning?
>> I should also specify that the process being waited on is not a
>> child process-it's just some other process on the system.
>Umm... Any details on intended use? IOW, is that "I want to write
>an utility that would wait for given PID to exit, just for the hell
>of it" or is there something you are trying to implement using that?

I'm trying to implement pwait. It blocks until a specified PID exits,
and then it exits.

You can use it to do other stuff after a program finishes.

While we're on the subject, is there some way to receive notification
that some aspect of a process changes (in this case, stopping using
CPU, but not exiting).

Thanks for the time to help me figure this out.

-Joseph

--
tre...@digitasaru.net.///////////////////////////////////////////////
"There is also an entire branch in the physical therapy field dedicated
to the treatment of little-finger injuries caused by excessive Emacs
use." --Linux Weekly News editor (http://lwn.net/Articles/206916/)
///////260 IATL / The University of Iowa / Iowa City, IA 52242///////

Kyle McMartin

unread,
Jul 30, 2007, 11:49:08 PM7/30/07
to Joseph Pingenot, linux-...@vger.kernel.org
On Mon, Jul 30, 2007 at 10:40:59PM -0500, Joseph Pingenot wrote:
> From Al Viro on Tuesday, 31 July, 2007:
> >On Mon, Jul 30, 2007 at 10:31:13PM -0500, Joseph Pingenot wrote:
> >> >From Joseph Pingenot on Monday, 30 July, 2007:
> >> >From Al Viro on Tuesday, 31 July, 2007:
> >> >>On Mon, Jul 30, 2007 at 09:16:16PM -0500, Joseph Pingenot wrote:
> >> >>> I was trying to use inotify to watch process changes (especially process
> >> >>> termination) by watching /proc/<pid>.
> >> >>> Sadly, although I could see something reading various files, nothing
> >> >>> was issued when the process I was watching exited and the directory
> >> >>> went away.
> >> >>> Is this intentional, or a bug?
> >> >>It's a bug you intend to introduce in your program... IOW, don't
> >> >>do that.
> >> >More background, please?
> >> >What's the way to check for a process exiting without spinning?
> >> I should also specify that the process being waited on is not a
> >> child process-it's just some other process on the system.
> >Umm... Any details on intended use? IOW, is that "I want to write
> >an utility that would wait for given PID to exit, just for the hell
> >of it" or is there something you are trying to implement using that?
>
> I'm trying to implement pwait. It blocks until a specified PID exits,
> and then it exits.
>

ptrace with options set to PTRACE_O_TRACEEXIT?

--Kyle

Al Viro

unread,
Jul 30, 2007, 11:50:56 PM7/30/07
to linux-...@vger.kernel.org
On Mon, Jul 30, 2007 at 10:40:59PM -0500, Joseph Pingenot wrote:
> I'm trying to implement pwait. It blocks until a specified PID exits,
> and then it exits.

er... ptrace(2)?

Joseph Pingenot

unread,
Jul 30, 2007, 11:57:57 PM7/30/07
to Al Viro, linux-...@vger.kernel.org
From Al Viro on Tuesday, 31 July, 2007:
>On Mon, Jul 30, 2007 at 10:40:59PM -0500, Joseph Pingenot wrote:
>> I'm trying to implement pwait. It blocks until a specified PID exits,
>> and then it exits.
>er... ptrace(2)?

Should work for most common usage scenarios, although will suspect that it
won't for for processes owned by another user (at least, I hope
it wouldn't).

What is dangerous about inotify on a proc file?

--
tre...@digitasaru.net.///////////////////////////////////////////////
"There is also an entire branch in the physical therapy field dedicated
to the treatment of little-finger injuries caused by excessive Emacs
use." --Linux Weekly News editor (http://lwn.net/Articles/206916/)
///////260 IATL / The University of Iowa / Iowa City, IA 52242///////

Al Viro

unread,
Jul 31, 2007, 12:01:47 AM7/31/07
to linux-...@vger.kernel.org
On Mon, Jul 30, 2007 at 10:56:27PM -0500, Joseph Pingenot wrote:
> >From Al Viro on Tuesday, 31 July, 2007:
> >On Mon, Jul 30, 2007 at 10:40:59PM -0500, Joseph Pingenot wrote:
> >> I'm trying to implement pwait. It blocks until a specified PID exits,
> >> and then it exits.
> >er... ptrace(2)?
>
> Should work for most common usage scenarios, although will suspect that it
> won't for for processes owned by another user (at least, I hope
> it wouldn't).
>
> What is dangerous about inotify on a proc file?

Playing with the lifetime rules, for starters...

Chris Friesen

unread,
Jul 31, 2007, 1:49:38 AM7/31/07
to tre...@digitasaru.net, Al Viro, linux-...@vger.kernel.org
Joseph Pingenot wrote:

> While we're on the subject, is there some way to receive notification
> that some aspect of a process changes (in this case, stopping using
> CPU, but not exiting).

For some internal stuff a while back I did a patch that allows any
process to register for status change notifications. Basically, the
registered process gets put on a list and gets the same notifications
(killed/stopped/exited, etc.) as the real parent.

Useful for this type of thing.

Chris

Ray Lee

unread,
Jul 31, 2007, 11:51:13 AM7/31/07
to tre...@digitasaru.net, Al Viro, linux-...@vger.kernel.org
On 7/30/07, Joseph Pingenot <tre...@digitasaru.net> wrote:
> What's the way to check for a process exiting without spinning?

I think you can get it from the taskstats interface, though I haven't
tried it. See Documentation/accounting/ for details.

Ray

Diego Calleja

unread,
Jul 31, 2007, 2:32:46 PM7/31/07
to tre...@digitasaru.net, Al Viro, linux-...@vger.kernel.org
El Mon, 30 Jul 2007 22:25:21 -0500, Joseph Pingenot <tre...@digitasaru.net> escribió:

> More background, please?
>
> What's the way to check for a process exiting without spinning?


I don't know if it's useful for you, but CONFIG_CONNECTOR and CONFIG_PROC_EVENTS
will report process creation/exit/fork/etc through a netlink interface.

Andrew Morton

unread,
Jul 31, 2007, 8:42:42 PM7/31/07
to Diego Calleja, tre...@digitasaru.net, Al Viro, linux-...@vger.kernel.org
On Tue, 31 Jul 2007 20:31:49 +0200 Diego Calleja <die...@gmail.com> wrote:

> El Mon, 30 Jul 2007 22:25:21 -0500, Joseph Pingenot <tre...@digitasaru.net> escribió:
>
> > More background, please?
> >
> > What's the way to check for a process exiting without spinning?
>
>
> I don't know if it's useful for you, but CONFIG_CONNECTOR and CONFIG_PROC_EVENTS
> will report process creation/exit/fork/etc through a netlink interface.

yup. See example code in Documentation/accounting/getdelays.c

Valdis.K...@vt.edu

unread,
Jul 31, 2007, 9:33:55 PM7/31/07
to tre...@digitasaru.net, Al Viro, linux-...@vger.kernel.org
On Mon, 30 Jul 2007 22:56:27 CDT, Joseph Pingenot said:
> From Al Viro on Tuesday, 31 July, 2007:
> >On Mon, Jul 30, 2007 at 10:40:59PM -0500, Joseph Pingenot wrote:
> >> I'm trying to implement pwait. It blocks until a specified PID exits,
> >> and then it exits.
> >er... ptrace(2)?
>
> Should work for most common usage scenarios, although will suspect that it
> won't for for processes owned by another user (at least, I hope
> it wouldn't).
>
> What is dangerous about inotify on a proc file?

And if it's dangerous, should the inotify system call fail when trying to
set the watch? Bailout with a -EBADIDEA or something?

0 new messages