[lug] socket programming/kernel question

Buzbee, James James.Buzbee at echostar.com
Wed Mar 5 08:42:55 MST 2003


Bear Giles wrote:
> Any networking or kernel experts around?
> 
> If I have a stream connection and the other side disconnects, my process 
> gets an EPIPE signal.  That's simple to catch and use to release resources.
> 
> But what about a datagram Unix socket?  There's no connection, per se, 
> but I can use the SCM_CREDENTIALS to get the PID of the caller.  The 
> kernel will know when that process dies.  Is there any way for my 
> process to get a signal then an arbitrary process dies?


If you know the pid, you can tell if the pid is valid (i.e. there is a 
process running with that pid) by doing a "kill( pid, 0 );".  A signal 
of 0 sends no signal, it only does error checking. One of the possible 
return values is :  ESRCH  The pid or process group does not exist. 
Once you get the error, you know your former client is gone.

Of course this pre-supposes a number of things : You're only dealing 
with local clients, you have the privilege to do the "kill", polling 
your clients for pid status is acceptable, and you are not worried about 
pid re-use in your polling period.

Jim



> 
> (Why do I need this?  I'm working on an ephemeral server where each 
> process sees the same values every time it calls the server, but 
> different processes see different values.  SCM_CREDENTIALS get me most 
> of the way there, but Linux reuses pids.)
> 
> Bear
> 
> _______________________________________________
> Web Page:  http://lug.boulder.co.us
> Mailing List: http://lists.lug.boulder.co.us/mailman/listinfo/lug
> Join us on IRC: lug.boulder.co.us port=6667 channel=#colug
> 





More information about the LUG mailing list