Re: How to to kill a c program at the exit of my gui?
From: Melissa Schrumpf (reverse-comDOTyahooATm_schrumpf_at_bogus.address)
Date: 05/13/04
- Next message: Gerald W. Lester: "Re: For someone just learning...8.5 or 8.4.6?"
- Previous message: Gerald W. Lester: "Re: SQLEXEC"
- In reply to: Hao Xu: "How to to kill a c program at the exit of my gui?"
- Next in thread: Hao Xu: "Re: How to to kill a c program at the exit of my gui?"
- Reply:(deleted message) Hao Xu: "Re: How to to kill a c program at the exit of my gui?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Thu, 13 May 2004 08:30:40 -0400
Hao Xu wrote:
> 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?
Yes, this is feasible, but checking for a broken file descriptor is something
the running program must do, not tcl.
You have three options that I can think of, off the top of my head. On unix,
you can:
fd_set rset;
struct timeval t;
FD_ZERO(&rset);
FD_SET(STDIN_FILENO, &rset);
t.tv_sec = 0;
t.tv_usec = 1;
while(1) {
if ((select(STDIN_FILENO+1), &rset, NULL, NULL, &t)>0) {break;}
// ...
}
On Windows, you can:
while(!_kbhit()) {
if (ferror(stdout) || ferror(stdin) ||
feof(stdout) || feof(stdin)) {break;}
// ...
}
On either platform, you could wait until you expect no more user input (your
normal I/O is complete), then spawn a thread, and have that thread do a
blocking read (getc()) on stdin, then check for ferror or feof on stdin when
getc completes.
-- MKS
- Next message: Gerald W. Lester: "Re: For someone just learning...8.5 or 8.4.6?"
- Previous message: Gerald W. Lester: "Re: SQLEXEC"
- In reply to: Hao Xu: "How to to kill a c program at the exit of my gui?"
- Next in thread: Hao Xu: "Re: How to to kill a c program at the exit of my gui?"
- Reply:(deleted message) Hao Xu: "Re: How to to kill a c program at the exit of my gui?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|