How to to kill a c program at the exit of my gui?

From: Hao Xu (hxu_at_mail.linx-info.com)
Date: 05/13/04


Date: Thu, 13 May 2004 15:07:27 +0800

Hi averyone!

  I wrote a C program to receive interesting things from gateway. It's
name is recv. I also wrote a TclTk gui to control this prog.

  set fd [open "|/usr/local/bin/recv" r+]

  When start up, this program reads username and password from stdin(now
redirected to $fd) for authentication, and after authentication, the
program does not need to read anything more from $fd, it enters an
while(1) loop to read the socket.

  Now I found that after the exit of the TclTk gui, the recv program is
still running, which is not what I want.

  I know that I can kill the recv program by "exec kill [pid $fd]", but
I don't want to terminate the program this way.

  I think that at the exit of the TclTk gui, the $fd breaks, and there
is EOF of stdin, isn't it? So I want the recv program to know this
signal, and use the corresponding signal handler to kill itself.

  My question is:
    Is this feasible? If the answer is yes, then how to do this?

  Thank you!

  X.H.



Relevant Pages

  • Re: How to to kill a c program at the exit of my gui?
    ... >name is recv. ... I also wrote a TclTk gui to control this prog. ... >I don't want to terminate the program this way. ... and use the corresponding signal handler to kill itself. ...
    (comp.lang.tcl)
  • Re: recv(), SIGNAL and loosing data
    ... You should just block SIGUSR1 handling before invoking recv() and set ... signal handler back after recvreturns. ... > The problem is that I loose data! ...
    (comp.os.linux.development.apps)
  • Re: how to avoid recv() blocking issue?
    ... exit. ... However, because of that possibility, all my calls to blocking recv use ... zero (indicating that the connection was closed). ...
    (microsoft.public.win32.programmer.networks)