Skip to contentSkip to conversation

inotify and /proc/<pid>

DISCUSSION Joseph Pingenot 8 participants 16 messages Jul 31, 2007 – Aug 1, 2007

lore
Share & tools
lore
#0 lore raw

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

Signature · 5 lines
[email protected].///////////////////////////////////////////////
"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///////
#1 lore raw
Quoted 8 lines · Joseph Pingenot

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.

#2 lore raw
Quoted 10 lines

From Al Viro on Tuesday, 31 July, 2007:

Quoted 6 lines · Joseph Pingenot

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

Signature · 5 lines
[email protected].///////////////////////////////////////////////
"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///////
#3 lore raw
Quoted 8 lines · Joseph Pingenot
Quoted 8 lines

From Al Viro on Tuesday, 31 July, 2007:

Quoted 6 lines · Joseph Pingenot

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?

Quoted 6 lines
Quoted 2 lines

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...

#4 lore raw
In reply to Joseph Pingenot
Quoted 9 lines

From Joseph Pingenot on Monday, 30 July, 2007:
From Al Viro on Tuesday, 31 July, 2007:

Quoted 7 lines · Joseph Pingenot
Quoted 6 lines

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?

Quoted 4 lines
Quoted 2 lines

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.

Signature · 5 lines
[email protected].///////////////////////////////////////////////
"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///////
#5 lore raw
Quoted 9 lines · Joseph Pingenot
Quoted 9 lines

From Joseph Pingenot on Monday, 30 July, 2007:
From Al Viro on Tuesday, 31 July, 2007:

Quoted 7 lines · Joseph Pingenot
Quoted 6 lines

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?

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

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?

#6 lore raw
Quoted 13 lines

From Al Viro on Tuesday, 31 July, 2007:

Quoted 11 lines · Joseph Pingenot
Quoted 11 lines

From Joseph Pingenot on Monday, 30 July, 2007:
From Al Viro on Tuesday, 31 July, 2007:

Quoted 9 lines · Joseph Pingenot
Quoted 6 lines

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.

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

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

Signature · 5 lines
[email protected].///////////////////////////////////////////////
"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///////
#7 lore raw
Quoted 15 lines · Joseph Pingenot

From Al Viro on Tuesday, 31 July, 2007:

Quoted 14 lines · Joseph Pingenot
Quoted 13 lines
Quoted 13 lines

From Joseph Pingenot on Monday, 30 July, 2007:
From Al Viro on Tuesday, 31 July, 2007:

Quoted 9 lines · Joseph Pingenot
Quoted 6 lines

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?

Quoted 9 lines
Quoted 5 lines
Quoted 2 lines

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

#9 lore raw
Quoted 5 lines

From Al Viro on Tuesday, 31 July, 2007:

Quoted 2 lines · Joseph Pingenot

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?

Signature · 5 lines
[email protected].///////////////////////////////////////////////
"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///////
#10 lore raw
Quoted 11 lines · Joseph Pingenot
Quoted 5 lines

From Al Viro on Tuesday, 31 July, 2007:

Quoted 2 lines · Joseph Pingenot

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...

#11 lore raw
In reply to Joseph Pingenot
Quoted 11 lines · Joseph Pingenot

From Al Viro on Tuesday, 31 July, 2007:

Quoted 4 lines · Joseph Pingenot
Quoted 2 lines

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?

#12 lore raw
In reply to Joseph Pingenot
Quoted 3 lines · Joseph Pingenot

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

#13 lore raw
In reply to Joseph Pingenot
Quoted 1 line · Joseph Pingenot

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

#14 lore raw
In reply to Joseph Pingenot
Quoted 3 lines · Joseph Pingenot

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.

#15 lore raw
Quoted 9 lines · On Tue, 31 Jul 2007 20:31:49 +0200 Diego Calleja <[email protected]> wrote:
Quoted 3 lines · Joseph Pingenot

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