Solved

Detecting of clicking on STOP-button

Posted on 1997-10-03
13
165 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Learn by Doing. Anytime. Anywhere.

Do you like to learn by doing?
Our labs and exercises give you the chance to do just that: Learn by performing actions on real environments.

Hands-on, scenario-based labs give you experience on real environments provided by us so you don't have to worry about breaking anything.

 
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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

It is becoming increasingly popular to have a front-page slider on a web site. Nearly every TV website,  magazine or online news has one on their site, and even some e-commerce sites have one. Today you can use sliders with Joomla, WordPress or …
The Windows functions GetTickCount and timeGetTime retrieve the number of milliseconds since the system was started. However, the value is stored in a DWORD, which means that it wraps around to zero every 49.7 days. This article shows how to solve t…
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…
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 …

696 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