Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Detecting of clicking on STOP-button

Posted on 1997-10-03
13
Medium Priority
?
168 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
[Webinar] Cloud Security

In this webinar you will learn:

-Why existing firewall and DMZ architectures are not suited for securing cloud applications
-How to make your enterprise “Cloud Ready”, and fix your aging DMZ architecture
-How to transform your enterprise and become a Cloud Enabler

 
LVL 85

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 85

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 85

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This tutorial will discuss the log-in process using WhizBase. In this article I assume you already know HTML. I will write the code using WhizBase Server Pages, so you need to know some basics in WBSP (you might look at some of my other articles abo…
A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

916 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