Solved

Detecting of clicking on STOP-button

Posted on 1997-10-03
13
164 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
Major Incident Management Communications

Major incidents and IT service outages cost companies millions. Often the solution to minimizing damage is automated communication. Find out more in our Major Incident Management Communications infographic.

 
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

Suggested Solutions

In this tutorial I will show you how to provide a dynamic RTF document on your website generated with data from your database. For this tutorial you will need Microsoft Word or WordPad, WhizBase and Microsoft Access. In this tutorial I will show …
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

732 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