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.

Application trigger on USB arrival

Hi Experts,

I want to load the driver and to trigger an application when the USB device is arrived.

What is the best feasible way to do it ?

Also the application should be killed and the driver should be unloaded when the interface is removed.

  • Hi,
    I hope, we had discussed already about this.
    Still, you are not able to find out the solution ?

    As I told you earlier and now Clemens also mentioned the same that we can use "udev" rules to trigger the scripts to do your stuff(loading,unloading etc.,).
  • Hi Titus,

    Yeah we already had few discussions.

    I am trying to load the kernel driver and the application to access the kernel driver as well.

    In that case, I am facing issues like

    1. Only absolute path is working in the shell scripts. (Like everything starts from "/home/" or "/")

    2. I am not able to know the status of running application inside the shell script.

    3. I am not able to get some trace prints. Right now am dumping in the file. (As echo "Error occurred in app" >/usr/log/mylog)


    Also is the same udev rules work for device removal as well ?

    Regards,

    Lyf

  • Hi,
    Yes, we can use script to run for USB device removal.
    I'm not clear on your requirement.
    Could you explain a bit on your requirement.
  • I am trying to load the kernel driver

    If the driver is written correctly, it is loaded automatically.

    Only absolute path is working in the shell scripts.

    And why is that a problem?

    I am not able to know the status of running application inside the shell script.

    Then the application and the script must work together somehow. (For example, the application could create a PID file. Or just try to terminate the application by name, with killall.)

    I am not able to get some trace prints.

    Scripts run by udev indeed are not connected to any terminal. You can redirect the output to a file, or to the system log (logger).

    Also is the same udev rules work for device removal as well ?

    No, you have to replace ACTION="add" with ACTION="remove".