LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-05-2008, 07:00 AM   #1
linuxdoniv
Member
 
Registered: Mar 2008
Posts: 63

Rep: Reputation: 15
inotify does not work on /proc


Hi,

I wrote a simple inotify program for monitoring the changes in a file system.

But the code seems to work for other directories except /proc.


#include <stdio.h>
#include <stdlib.h>
#include <sys/inotify.h>
#include <sys/types.h>
#define EVENT_SIZE (sizeof (struct inotify_event))
#define BUF_LEN (1024 * (EVENT_SIZE + 16) )


int
main (int argc, char *argv[])
{
int wd;

int fd;

char buf[BUF_LEN];

int len, i = 0;

fd = inotify_init ();

if (fd < 0)
{
exit (-1);
}

wd = inotify_add_watch (fd, "/proc", IN_CREATE);

if (wd < 0)
exit(-1);
else
{
len = read (fd, buf, BUF_LEN);

while (i < len)
{
struct inotify_event *event;

event = (struct inotify_event *) &buf[i];

printf ("wd=%d mask=%u cookie=%u len=%u\n",
event->wd, event->mask, event->cookie, event->len);

if (event->len)
printf ("name=%s\n", event->name);

i += EVENT_SIZE + event->len;
}

}

return 0;
}








Could any body help me...

Thanks.
 
Old 08-05-2008, 07:55 AM   #2
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,356

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
/proc is just a window onto the kernel structures, its not a real filesystem, so I'm not surprised.
 
Old 08-05-2008, 09:23 AM   #3
linuxdoniv
Member
 
Registered: Mar 2008
Posts: 63

Original Poster
Rep: Reputation: 15
Hi,

Could you please tell me how can I get notified when a new process enters the system. I was thinking that I could use inotify..

Thanks..
 
Old 08-05-2008, 09:38 AM   #4
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,356

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
Unless this is a stripped down eg embedded system, you would get swamped. Processes are continuously being created by various bits of SW.
Why would you want to do this?
 
Old 08-06-2008, 02:17 AM   #5
linuxdoniv
Member
 
Registered: Mar 2008
Posts: 63

Original Poster
Rep: Reputation: 15
I would like to profile the process using the information in /proc/pid.

Its okey even if it is few thousands since I dont do much processing on every process created.

Thanks,
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Boot hang after 'proc on /proc type proc (rw)' Hagoromo Slackware 13 10-05-2007 05:03 PM
/proc/pid/io seems not to work kornelix Linux - Server 5 06-17-2007 02:39 AM
udev and inotify aeruzcar Linux - General 3 03-24-2007 12:42 PM
Mounting Inotify? trscookie Linux - Software 1 12-19-2005 01:37 PM
Can linux work without /proc? mrpc_cambodia Red Hat 2 10-07-2004 01:41 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:58 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration