We are developing an embedded device running Linux, which needs to act as a usb serial gadget and connect to android phones for different types of data transfer. In order to initiate the communication with the host usb (android phone), I need to detect whenever the USB host is connected to the device. I came to know about writing udev rules in order to run an executable on usb host insertion/removal, but We already have a main C program that manages all of the device's main functionality. I would be running a thread in this program which would be responsible for this communication. Is there any way by which I can receive the USB hotplug event in this thread. I am really trying to avoid using loops in this thread so that it doesn't get CPU intensive. So is there any way by which I can receive the USB hotplug event?