This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

USB removal notification not received for udev

Hi Experts,

I am invoking the program A which executes in infinite loop when the USB device is added using the udev rules file.

When I remove the USB device the remove notification is not processed until the program A is killed.


As soon as the program A is killed then the removal notification is processed.

I want to invoke a program during the arrival notification and needs to kill the same when it is plugged out.

Regards,

Lyf

  • Hi Lyf,

    Does the udev creates and removes the device nodes without invoking the Program A?
    Does the udev works fine normally during the insertion and removal of USB device?

    --
  • Hi Shankari,

    Its been long time I guess and hope things are fine.

    Yeah the udev works fine when the progarm A is exited properly. The problem is when Program A is active then other subsequent notifications are queued.

    Regards,
    Lyf
  • Any suggestions ??

    Regards,
    Lyf
  • Hi Lyf,

    More over this query seems to be a general Linux query. If you google it, you will get some stuffs.

    --
  • Hi Lyf,

    When we experimented, we are able to see the same behaviour and then able to fix it.The ambersand did the magic here. I mean, when we run the program in background, we will be able to detect the removal.

    We successfully created and invoked a program while connecting the pendrive and destroyed the program while disconnecting the pendrive.

    1. /etc/udev/rules.d/local.rules

    ACTION=="add", SUBSYSTEM=="usb", ENV{ID_VENDOR_ID}=="03f0", ENV{ID_MODEL_ID}=="2340", RUN+="/etc/udev/scripts/usb_add.sh"
    ACTION=="remove", SUBSYSTEM=="usb", ENV{ID_VENDOR_ID}=="03f0", ENV{ID_MODEL_ID}=="2340", RUN+="/etc/udev/scripts/usb_remove.sh"

    2. /etc/udev/scripts/usb_add.sh

    #!/bin/sh
    mkdir /usb_add
    ./hello.out &

    3. /etc/udev/scripts/usb_remove.sh

    #!/bin/sh
    mkdir /usb_remove
    killall hello.out

    -------

  • Hi Shankari,

    Thanks for the efforts.

    I already tried the same. The issue is I used

    "sudo ./hello.out >err &" instead of "./hello.out >err &"

    In that case the hello.out is not created as seperate thread which leads to the issue.

    Thanks for solving it.

    Regards,
    Lyf