Automatically flush PF_UNIX sockets when exiting a process?

Can I clear UNIX domain sockets automatically when the process that created them is complete?

+4
source share
2 answers

If your application needs to be run only on Linux, you can use an abstract unix socket (a socket where the path starts with a NULL byte). Abstract sockets are automatically cleared when the server process completes.

+1
source

Either by fixing the application so that it deletes (disconnects) the socket file on exit, or if you know the location of the socket file:

fuser sockfile.sock || rm sockfile.sock 

This checks if the process uses the file and if it does rm if it does not. You can put this in a shell script that actually executes the application and subsequently flushes the socket file.

0
source

Source: https://habr.com/ru/post/1402513/


All Articles