#24 > Using inotifywait on /proc works fine too.
False, it does not notify you of new entries (like new processes
launched). Try the program below for proof; launch it and run "sleep
999" and you will not see the PID of your new sleep appear printed out.
Using inotify with /proc/ will probably never work, because the /proc/
entries are not files. They don't get updated until you look at them.
It's not a bug, it's a design "feature". See
http://unix.stackexchange.com/questions/74713/how-frequently-is-the-
proc-file-system-updated-on-linux?rq=1
If you want to monitor new procs under Linux, use a socket with
NETLINK_CONNECTOR instead.
#include <stdlib.h>
#include <stdio.h>
#include <sys/inotify.h>
int main(int argc, char* argv[]){
int inotify_fd = inotify_init();
if (inotify_fd == -1) {
perror("inotify_init(): ");
}
// int watch_descriptor = inotify_add_watch(inotify_fd, "/proc", IN_CREATE);
int watch_descriptor = inotify_add_watch(inotify_fd, "/proc",
IN_ALL_EVENTS);
if (watch_descriptor == -1) {
perror("inotify_add_watch(): ");
}
struct inotify_event *event;
char buf[1024];
ssize_t result;
// Watch forever, until signal (CTRL-C, etc.)
while(1)
{
result = read(inotify_fd, buf, sizeof(buf));
if (result == -1){
perror("read(): ");
}
// Print all events read from inotify_fd:
int index = 0;
while (index < result) {
event = (void *)(&buf[index]);
printf("index %d: %s\n", (int)index, event->name);
index += sizeof(struct inotify_event) + event->len;
}
printf("\n");
}
}
--
You received this bug notification because you are a member of Ubuntu
Bugs, which is subscribed to Ubuntu.
https://bugs.launchpad.net/bugs/454722
Title:
inotify does not watch /proc
To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/linux/+bug/454722/+subscriptions
--
ubuntu-bugs mailing list
[email protected]
https://lists.ubuntu.com/mailman/listinfo/ubuntu-bugs