Solved

Detecting of clicking on STOP-button

Posted on 1997-10-03
13
160 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
 
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

Introduction This tutorial will give you a fast look what you can do with WhizBase. I expect you already know how to work with HTML at least, and that you understand the basics of the internet and how the internet works. WhizBase is a server-s…
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 viewer will learn how to count occurrences of each item in an array.
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 …

762 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now