inotify does not watch /proc

Bug #454722 reported by Angelo Borsotti
26
This bug affects 4 people
Affects Status Importance Assigned to Milestone
linux (Ubuntu)
Won't Fix
Undecided
Unassigned

Bug Description

Compile the following program (inotifyerr.c)

#include <stdlib.h>
#include <stdio.h>
#include <sys/inotify.h>

int main(int argc, char* argv[]){
    int fd = inotify_init();
    if (fd == -1){
        perror("inotify_init");
    }
    char path[256];
    sprintf(path,"/proc/%s",argv[1]);
    printf("watching %s\n",path);
    int wd = inotify_add_watch(fd,path,IN_ALL_EVENTS);
    if (wd == -1){
        perror("inotify_add_watch");
    }
    char buf[1024];
    ssize_t siz = read(fd,buf,1024);
    if (siz == -1){
        perror("inotify read");
    }
    printf("read done, bytes: %d\n",siz);
}

gcc inotifyerr.c

The program is supposed to watch events occurring on file /proc/nnn, where nnn is passed as
argument to program invokation.
Then start a process in background, and watch it with the program above. E.g.

$ sleep 20 &
[1] 8246
$ ls /proc/8246
attr cpuset io mountinfo pagemap smaps wchan
auxv cwd latency mounts personality stat
cgroup environ limits mountstats root statm
clear_refs exe loginuid net sched status
cmdline fd maps oom_adj schedstat syscall
coredump_filter fdinfo mem oom_score sessionid task
$ ./a.out 8246
watching /proc/8246
^C
[1]+ Done sleep 20

Note that the background process and the inotifyerr one are run from
within the same terminal, same user, and that the latter has read
access to the file being watched.
No events are reported.

The expected behaviour of inotify is to report events on /proc files
and directories instead.

Additional information:
I have run the same test also with superuser privileges, but the result
is the same.
I have modified the test program so as to make the process to whatch
a child of the inotifyerr one. In this case inotify catches all the events.

Ubuntu 9.04. 2.6.28-15-generic #52-Ubuntu SMP Wed Sep 9 10:49:34 UTC 2009 i686 GNU/Linux
---
AlsaVersion: Advanced Linux Sound Architecture Driver Version 1.0.21.
Architecture: i386
AudioDevicesInUse:
 USER PID ACCESS COMMAND
 /dev/snd/controlC0: angelo 1376 F.... pulseaudio
CRDA: Error: [Errno 2] No such file or directory
Card0.Amixer.info:
 Card hw:0 'NVidia'/'HDA NVidia at 0xfe028000 irq 23'
   Mixer name : 'Realtek ALC888'
   Components : 'HDA:10ec0888,1631e601,00100001'
   Controls : 37
   Simple ctrls : 21
DistroRelease: Ubuntu 10.04
HibernationDevice: RESUME=UUID=335bd2d5-504f-4410-a53a-96814ee336e8
InstallationMedia: Ubuntu 10.04 LTS "Lucid Lynx" - Release i386 (20100429)
Lsusb:
 Bus 002 Device 002: ID 046d:c315 Logitech, Inc. Classic New Touch Keyboard
 Bus 002 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
 Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
MachineType: Packard Bell BV IMEDIA 8425
NonfreeKernelModules: nvidia
Package: linux (not installed)
ProcCmdLine: BOOT_IMAGE=/boot/vmlinuz-2.6.32-24-generic root=UUID=2258e664-9423-4566-ae33-52c12a4645ec ro quiet splash
ProcEnviron:
 LANG=en_US.utf8
 SHELL=/bin/bash
ProcVersionSignature: Ubuntu 2.6.32-24.41-generic 2.6.32.15+drm33.5
Regression: No
RelatedPackageVersions: linux-firmware 1.34.1
Reproducible: Yes
RfKill:
 0: phy0: Wireless LAN
  Soft blocked: no
  Hard blocked: no
Tags: lucid filesystem needs-upstream-testing
Uname: Linux 2.6.32-24-generic i686
UserGroups: adm admin cdrom dialout lpadmin plugdev sambashare
dmi.bios.date: 11/01/2006
dmi.bios.vendor: Phoenix Technologies, LTD
dmi.bios.version: M2N-NM 0401
dmi.board.name: M2N-NM
dmi.board.vendor: Packard Bell BV
dmi.board.version: 1.XX
dmi.chassis.asset.tag: 123456789000
dmi.chassis.type: 3
dmi.chassis.vendor: Packard Bell BV
dmi.chassis.version: Chassis Version
dmi.modalias: dmi:bvnPhoenixTechnologies,LTD:bvrM2N-NM0401:bd11/01/2006:svnPackardBellBV:pnIMEDIA8425:pvrPB80107506:rvnPackardBellBV:rnM2N-NM:rvr1.XX:cvnPackardBellBV:ct3:cvrChassisVersion:
dmi.product.name: IMEDIA 8425
dmi.product.version: PB80107506
dmi.sys.vendor: Packard Bell BV

Revision history for this message
Fabio Marconi (fabiomarconi) wrote :

Hello Angelo
is this problem present with the latest updated Karmic's or Lucid's packages?
Thanks in advance
Fabio

Changed in ubuntu:
status: New → Incomplete
Revision history for this message
Angelo Borsotti (angelo-borsotti) wrote : Re: [Bug 454722] Re: inotify does not watch /proc

Hi Fabio,

yes, the same problem occurs in lucid. I have tested it right now and have
seen that
inotify does not work as expected.

-Angelo

tags: added: karmic lucid
affects: ubuntu → linux (Ubuntu)
Changed in linux (Ubuntu):
status: Incomplete → Confirmed
Revision history for this message
Fabio Marconi (fabiomarconi) wrote :

Hello Angelo

can you please run in a terminal:
apport-collect 454722
Thanks
Fabio

Changed in linux (Ubuntu):
status: Confirmed → Incomplete
Revision history for this message
Angelo Borsotti (angelo-borsotti) wrote : AlsaDevices.txt

apport information

tags: added: apport-collected
description: updated
Revision history for this message
Angelo Borsotti (angelo-borsotti) wrote : AplayDevices.txt

apport information

Revision history for this message
Angelo Borsotti (angelo-borsotti) wrote : ArecordDevices.txt

apport information

Revision history for this message
Angelo Borsotti (angelo-borsotti) wrote : BootDmesg.txt

apport information

Revision history for this message
Angelo Borsotti (angelo-borsotti) wrote : Card0.Amixer.values.txt

apport information

Revision history for this message
Angelo Borsotti (angelo-borsotti) wrote : Card0.Codecs.codec.0.txt

apport information

Revision history for this message
Angelo Borsotti (angelo-borsotti) wrote : CurrentDmesg.txt

apport information

Revision history for this message
Angelo Borsotti (angelo-borsotti) wrote : IwConfig.txt

apport information

Revision history for this message
Angelo Borsotti (angelo-borsotti) wrote : Lspci.txt

apport information

Revision history for this message
Angelo Borsotti (angelo-borsotti) wrote : PciMultimedia.txt

apport information

Revision history for this message
Angelo Borsotti (angelo-borsotti) wrote : ProcCpuinfo.txt

apport information

Revision history for this message
Angelo Borsotti (angelo-borsotti) wrote : ProcInterrupts.txt

apport information

Revision history for this message
Angelo Borsotti (angelo-borsotti) wrote : ProcModules.txt

apport information

Revision history for this message
Angelo Borsotti (angelo-borsotti) wrote : UdevDb.txt

apport information

Revision history for this message
Angelo Borsotti (angelo-borsotti) wrote : UdevLog.txt

apport information

Revision history for this message
Angelo Borsotti (angelo-borsotti) wrote : WifiSyslog.txt

apport information

Revision history for this message
Fabio Marconi (fabiomarconi) wrote :

Thanks for reporting this bug and any supporting documentation. Since this bug has enough information provided for a developer to begin work, I'm going to mark it as confirmed and let them handle it from here. Thanks for taking the time to make Ubuntu better!

Changed in linux (Ubuntu):
status: Incomplete → Confirmed
Revision history for this message
Joseph Salisbury (jsalisbury) wrote : Unsupported series, setting status to "Won't Fix".

This bug was filed against a series that is no longer supported and so is being marked as Won't Fix. If this issue still exists in a supported series, please file a new bug.

This change has been made by an automated script, maintained by the Ubuntu Kernel Team.

Changed in linux (Ubuntu):
status: Confirmed → Won't Fix
Revision history for this message
Angelo Borsotti (angelo-borsotti) wrote : Re: [Bug 454722] Re: inotify does not watch /proc

Hi Joseph

it is a bit sad to spend time to isolate a bug, file it, provide all
the additional data asked, see it "confirmed" and then see that it has
been dropped because bug fixing has taken so much time as to make the
OS release obsolete.
Anyway, knowing that bugs that are not resolved in one Linux release
are very likely to be present also in the next, I made again the same
test: the problem is still there in 12.10.
Do you need me to file another bug, or can you resurrect it?

-Angelo

On 16 November 2012 23:51, Joseph Salisbury
<email address hidden> wrote:
> This bug was filed against a series that is no longer supported and so
> is being marked as Won't Fix. If this issue still exists in a supported
> series, please file a new bug.
>
> This change has been made by an automated script, maintained by the
> Ubuntu Kernel Team.
>
> ** Changed in: linux (Ubuntu)
> Status: Confirmed => Won't Fix
>
> --
> You received this bug notification because you are subscribed to the bug
> report.
> 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

Revision history for this message
john miller (johnmille1) wrote :

I am facing this same issue on other linux distros. The most I could find about it was in a linux-kernel thread from 2006. At that time the kernel was not designed to support inotify on proc. Hopefully ubuntu can make some progress. There were some proposals for alternate methods in the thread, maybe they can be of help. http://help.lockergnome.com/linux/inotify-proc--ftopict486108.html

Revision history for this message
Removed by request (removed3425744) wrote :

I have tested this on Ubuntu 13.04 and it is working fine:

sworddragon@ubuntu:~/data$ sleep 20 &
[1] 3009
sworddragon@ubuntu:~/data$ ls /proc/3009
attr cgroup comm cwd fd latency map_files mountinfo net oom_adj pagemap sched smaps statm task
autogroup clear_refs coredump_filter environ fdinfo limits maps mounts ns oom_score personality schedstat stack status wchan
auxv cmdline cpuset exe io loginuid mem mountstats numa_maps oom_score_adj root sessionid stat syscall
sworddragon@ubuntu:~/data$ ./a.out 3009
watching /proc/3009
read done, bytes: 128

Using inotifywait on /proc works fine too.

Revision history for this message
Derek Simkowiak (ubuntu-cool-st) wrote :

#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");

    }
}

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.