473,842 Members | 1,401 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to stop program?

Hi All,
I have a php program which calls a c++ program using exec. However when
user presses stop button in the browser or closes it this program keeps
on running on the server. How can I stop it according to user's
actions.
Thanks in advance.
Sal

Jul 17 '05 #1
15 3836
shyren wrote:
Hi All,
I have a php program which calls a c++ program using exec. However when
user presses stop button in the browser or closes it this program keeps
on running on the server. How can I stop it according to user's
actions.
Thanks in advance.
Sal


How can you detect the user pressed the stop button or closed the browser?
--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===
Jul 17 '05 #2
I don't know how to detect that user pressed the stop button or closed
the browser. That is one part of the problem.
Sal
Jerry Stuckle a écrit :
shyren wrote:
Hi All,
I have a php program which calls a c++ program using exec. However when user presses stop button in the browser or closes it this program keeps on running on the server. How can I stop it according to user's
actions.
Thanks in advance.
Sal

How can you detect the user pressed the stop button or closed the

browser?

--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===


Jul 17 '05 #3
shyren wrote:
I don't know how to detect that user pressed the stop button or closed
the browser. That is one part of the problem.
Sal


That was more of a rhetorical question. The answer is: you can't.
--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===
Jul 17 '05 #4
shyren (sa********@yah oo.com) wrote:
: Hi All,
: I have a php program which calls a c++ program using exec. However when
: user presses stop button in the browser or closes it this program keeps
: on running on the server. How can I stop it according to user's
: actions.
: Thanks in advance.
: Sal

If the c++ program is sending data to the file handle that is going back
to the browser (normally stdout), then the c++ program _might_ receive an
error when it prints to stdout if the browser is stopped, depending on how
the web server works.

If a web server detected that the file handle to the browser was closed
then I suppose some web servers might signal the cgi. The script and its
children could arrange to be interupted by that.

I would experiment with those two things on the server in question to see
if your program can detect either one.

Both cases depend on the browser closing the socket when you hit the stop
button, which is not something you control.

--

This space not for rent.
Jul 17 '05 #5
NC
shyren wrote:

I have a php program which calls a c++ program using exec.
However when user presses stop button in the browser or closes
it this program keeps on running on the server. How can I stop
it according to user's actions.


1. Make sure PHP is not ignoring user's abort commands:

ignore_user_abo rt(false);

2. Write a function that would use exec() to send a kill
signal to the C++ program. On Unix, you could do
something like this:

function kill_my_cpp_pro g() {
// call 'ps -auxww' to get the list of running processes
// find the pid for your C++ program
// call 'kill [pid]' to stop your C++ program
}

Refer to your OS manual for details of ps and kill usage.

3. Register that function to be executed at shutdown:

register_shutdo wn_function('ki ll_my_cpp_prog' );

So when a user aborts, it will trigger execution of
kill_my_cpp_pro g()...

Cheers,
NC

Jul 17 '05 #6
On 20 May 2005 10:07:02 -0700, "NC" <nc@iname.com > wrote:
shyren wrote:

I have a php program which calls a c++ program using exec.
However when user presses stop button in the browser or closes
it this program keeps on running on the server. How can I stop
it according to user's actions.


1. Make sure PHP is not ignoring user's abort commands:

ignore_user_abo rt(false);

2. Write a function that would use exec() to send a kill
signal to the C++ program. On Unix, you could do
something like this:

function kill_my_cpp_pro g() {
// call 'ps -auxww' to get the list of running processes
// find the pid for your C++ program
// call 'kill [pid]' to stop your C++ program
}

Refer to your OS manual for details of ps and kill usage.

3. Register that function to be executed at shutdown:

register_shutdo wn_function('ki ll_my_cpp_prog' );

So when a user aborts, it will trigger execution of
kill_my_cpp_pr og()...


Changing to use proc_open so you can then use proc_terminate might also be
worth thinking about.

There's also posix_kill() for sending signals (but you still have to get the
pid first).

--
Andy Hassall / <an**@andyh.co. uk> / <http://www.andyh.co.uk >
<http://www.andyhsoftwa re.co.uk/space> Space: disk usage analysis tool
Jul 17 '05 #7
NC
Andy Hassall wrote:

1. Make sure PHP is not ignoring user's abort commands:

2. Write a function that would use exec() to send a kill
signal to the C++ program.

3. Register that function to be executed at shutdown:
Changing to use proc_open so you can then use proc_terminate might
also be worth thinking about.


Definitely.
There's also posix_kill() for sending signals (but you still
have to get the pid first).


Also, the POSIX extension is often disabled for security purposes...

Cheers,
NC

Jul 17 '05 #8
According to given suggestions I wrote a program for testing. To see
whether I capture the user's abort I write to the file in tmp directory
with writing permissions set. But still I am not able to detect it. i
am new to php and more help would be highly appreciated. Thanks..
_______________ _______________ ____

<?php
ignore_user_abo rt(false);
function kill_my_cpp_pro g()
{
$file=fopen("tm p/num","w");
fputs($file,"nu mber2");
fclose($file);
echo "in";
}
#for($i=0;$i<10 000000;$i++)
# echo $i;
exec("sleep 5");
register_shutdo wn_function('ki ll_my_cpp_prog' );
?>

Jul 17 '05 #9
shyren,

You should most likely move the register_shutdo wn_function to right
after the function kill_my_cpp_pro g as so:

<?php
ignore_user_abo ut(false);
function kill_my_cpp_pro g() {
...
}
register_shutdo wn_function('ki ll_my_cpp_prog' );
....

Because the way you have it now, it will not register the shutdown
function until the script completes.

Mike
Jul 17 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
2423
by: Harald Armin Massa | last post by:
I need to do some synchronisations like in a cron.job import time from threading import Thread class updater(Thread): def run(self): while True: do_updates() time.sleep(600)
8
2047
by: Eric Osman | last post by:
My javascript program has reason to want to stop. For example, function A has 5 lines, the second of which calls function B, which has 5 lines, the first of which calls function C. But function C discovers that something is very wrong so it does an "alert" saying something like Sorry, couldn't make the necessary connection
2
2376
by: Mike Bennett | last post by:
Does the .NET framework (using VB.NET) support the ability to programmatically STOP a device prior to its removal from the system? I have need to move data from a computer on one network to a computer on a different network. For various reasons, I am not allowed to join these networks. Additionally, neither computer is allowed to disconnect from its network to connect to the other network I have decided to use a USB jump drive to move the...
3
2475
by: prakashsha | last post by:
HI, I've an asp.net page which has a button. On click of the button the program queries the database and gets the result and displays the same.Now assume that my program takes 2 minutes to get the results.In the mean time if the user press Esc button to stop the process. The page will stop processing but my database connection will be trying to retrieve the records. How to solve this ??? Thanks in Adavance.
14
7488
by: electrician | last post by:
While running a program that exceeds the array limits it issues an alert. I want to then stop the program after filling in the output boxes with blanks. How do you stop the program? I have worked on this for days and tried searching the net, but have found nothing.
5
12812
by: darthghandi | last post by:
I've created a class to listen to all interfaces and do a BeginAccept(). Once it gets a connection, it passes the connected socket off and stores it in a List. Next, it continues to listen for more incoming connections and does the BeginAccpet() again. It does an infinite loop this way. My question is: What is the best way to stop this? I thought about putting a boolean in there, but then what if it's still waiting for an incoming...
1
3590
by: =?Utf-8?B?S2Vubnk=?= | last post by:
I have one bat file that contains a command to startup Java Program. Then, I would like to create a cluster job to call the bat file. In case of one computer is down, another computer can also call the bat file and startup my Java Program. For this purpose, I have tried to place the bat file into share drive of two computers which are cluster machine. Also, I used Generic Application to create a job to call my bat file and this job is...
8
2898
by: goron | last post by:
Hello, I am writing a computationally heavy program which I know will need to run for many hours. Therefore, I need to make it possible to stop the program at any time while it's running and save my progress in an external file so that later the program can be started again and continue from where it left off. What I don't know how to do is how to actually get the program to stop, but make sure it executes some functions to save its progress...
0
3288
by: =?Utf-8?B?am1hZ2FyYW0=?= | last post by:
My program needs to do X when someone 'starts using' their Windows user account, and it should do Y when they 'stop using' their Windows user account. By 'starts using' I mean they log on, unlock the desktop, resume from hibernate/sleep, or resume a session that was paused via Switch User. By 'stop using' I mean they lock the desktop, initiate a hibernate/sleep , or choose Switch User while logged on. For context, the program is a parental...
0
9876
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9717
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10950
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10681
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10318
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7045
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4506
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4096
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3148
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.