Parts of the code are as explained below:The kernel notifies the userspace like (udev) about new available devices by (1) Spawning a process or (2) a packet to a netlink socket on attach. Code taken directly from the kernel documentation: