Solved

Detecting of clicking on STOP-button

Posted on 1997-10-03
13
162 Views
Last Modified: 2013-12-25
Is there a way I can check if an user hits the STOP-button or the BACK-button?
I want to know this because my program crashes if someone hits those buttons while running.
Thus I must create a routine that starts when hitting one of the buttons.
0
Comment
Question by:Michel021497
  • 4
  • 3
  • 3
  • +2
13 Comments
 
LVL 7

Expert Comment

by:faster
ID: 1830725
What is your "program"?  if it is JAVA applet, then some of its methods will be invoked by the browser.
0
 
LVL 1

Author Comment

by:Michel021497
ID: 1830726
It's a C program. So no JAVA.
0
 
LVL 1

Author Comment

by:Michel021497
ID: 1830727
Edited text of question
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 84

Expert Comment

by:ozo
ID: 1830728
Where does your C program crash?
0
 
LVL 7

Expert Comment

by:faster
ID: 1830729
Well, yours is a c program, then where does it run?  Is it a CGI that runs on the server (unlikely) or a browser plugin (also unlikely) or an activex control?
0
 
LVL 1

Author Comment

by:Michel021497
ID: 1830730
The program writes in a file. Because it's not posible that 2 persons write in one file at the same time, I made a lock on the file.
 But if the STOP button is hit, the file is never unlocked.
So no one is able to use the program anymore after such action.
0
 
LVL 84

Expert Comment

by:ozo
ID: 1830731
Can you put a timeout on the lock?
Can you limit the lock window to times when the user is not upoading data?
0
 
LVL 7

Expert Comment

by:faster
ID: 1830732
You didn't answer my question, is it a CGI program or an activex control?
0
 
LVL 1

Author Comment

by:Michel021497
ID: 1830733
It's a CGI program.

0
 
LVL 2

Accepted Solution

by:
dmethvin earned 150 total points
ID: 1830734
When you click the browser's stop (or back) button, the browser closes the connection with the server. What happens after that isn't really defined by the CGI protocol as far as I can tell. On Apache the server will respond to your CGI program with a SIGPIPE if you try to write to stdout; you can catch that and do cleanup. (The default for an unhandled SIGPIPE is just to terminate the process, which would explain your lock problem.) If you're on a different server, you might try hooking all the signals and see if any get caught.
0
 
LVL 84

Expert Comment

by:ozo
ID: 1830735
Actually, I thought flock or lockf would release the lock when the process teminates.
0
 
LVL 5

Expert Comment

by:julio011597
ID: 1830736
No, no and no! This is not the answer, i'm afraid.

What happens after the client closes the connection is not defined by the CGI protocol because it has nothing to do with CGI; it has to do with handling socket connections.

And, you want get any SIGPIPE on any connection side, unless you _write_ to the socket.

Here is a scheme to handle the client closing the connection:

1. catch SIGALRM;
2. catch SIGPIPE; (handling EPIPE is another option)

3. setup a timer which interrupts your CGI process every N seconds;

4. in the SIGALRM handler, write - say - a new-line char to the socket; if the connection is closed, you'll get a SIGPIPE;

5. in the SIGPIPE handler, handle cleanup, because the socket has died.

The socket FAQ pages are the best reference on this kind of stuff (sorry, cannot remember the address).

Rgds, julio
0
 
LVL 2

Expert Comment

by:dmethvin
ID: 1830737
I think I said the same thing, didn't I? Stdout is mapped to a socket. You'll get a SIGPIPE if you write to stdout. The alarm isn't needed unless you're doing long stretches with no output and want to detect the stop, but it does generalize the solution nicely. (Never mind my lock comment, I was confusing this with another message.)
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Modifying Powershell script to get the size of the directory ? 2 58
create an incrementing variable name AutoHotKey 5 98
excel file 5 72
User profile Size Report 3 72
Recently I have been answering a lot of questions like this in IT forums that I frequent. The question posed is usually something along the lines of "We have software X installed and need to uninstall it for reason Y" or some other variant of the sa…
I hope you'll find this tutorial useful and interesting. So let's try to extend Tcl with a new package.  For anyone more deeply interested please check out the book "Practical Programming in Tcl and Tk". It's really one of the best written books abo…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

778 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question