gct
gct

Reputation: 14583

Automatically clean up PF_UNIX sockets on process exit?

Is there any way to have UNIX domain sockets be cleaned up automatically when the process that created them exits?

Upvotes: 4

Views: 1060

Answers (2)

gfxmonk
gfxmonk

Reputation: 8736

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

Upvotes: 2

Friek
Friek

Reputation: 1541

Either by fixing the application to let it delete (unlink) the socket file on exit, or if you know the location of the socket file:

fuser sockfile.sock || rm sockfile.sock

This checks if a process is using the file and executes an rm on it if it doesn't. You could put this in a wrapper script which actually executes the application and cleans up the socket file afterwards.

Upvotes: 0

Related Questions