473,480 Members | 1,839 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Killing processes

I need to execute a system command, read the printouts from its output
stream and be able to kill the process when needed. Is there any way
to accomplish all this in C/C++?

First I tried to use popen to open a pipe to the process, but then I
can't kill it since it doesn't return the pid. The only thing I can do
is to close the output stream by using pclose, but it waits for the
process to finish so it's of no use.

One possible way to do it is to use popen to get access to the output
stream and then use system commands to find out its pid, but there got
to be a better way, doesn't it?
Jul 22 '05 #1
1 2030
hepp wrote:
I need to execute a system command, read the printouts from its output
stream and be able to kill the process when needed. Is there any way
to accomplish all this in C/C++?
No, but you can accomplish the first step by calling the 'system'
function. All other steps can be done using OS-specific means.
First I tried to use popen to open a pipe to the process, but then I
can't kill it since it doesn't return the pid. The only thing I can do
is to close the output stream by using pclose, but it waits for the
process to finish so it's of no use.

One possible way to do it is to use popen to get access to the output
stream and then use system commands to find out its pid, but there got
to be a better way, doesn't it?


The better way is to use platform-specific functions to control processes.
However, they are OT here. Ask in a newsgroup for your platform/OS.

V
Jul 22 '05 #2

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

Similar topics

16
2961
by: Laura Conrad | last post by:
I'm writing an application that has to spawn some processes and then kill them later. It doesn't need to talk or listen to them while they're running, but there are stop and start buttons and the...
6
3454
by: Colin Steadman | last post by:
I have created a function to kill all session variables that aren't in a safe list. This is the function - Sub PurgeSessionVariables For Each Item In Session.Contents Select Case Trim(Item)...
10
9846
by: Jacek Popławski | last post by:
Hello. I am going to write python script which will read python command from socket, run it and return some values back to socket. My problem is, that I need some timeout. I need to say for...
2
1142
by: Stu | last post by:
Hi, I have an asp.net page that lists all running processes on the server using the script below: Dim p As Process For Each p In Process.GetProcesses sb.Append(p.ProcessName)...
39
2496
by: clintonG | last post by:
This is not about starting a fight but an observation that seems to be proving itself on its own merit and is therefore simply a point of conjecture. I did not get serious about writing software...
3
1061
by: _AnonCoward | last post by:
I want to create a program that can iterate through active processes and shut down certain applications that are running on a system. I need to ensure that these processes are not left running...
6
4598
by: laststubborn | last post by:
Hi everybody, We have a very large database and high transaction volume. Time to time these transactions are locking each other and decrease the performance of the database. Is there any way...
4
1602
by: Miro | last post by:
I'm using VB.Net 2003 I have code - it works great - to kill a process(s) if they are running. ---- Dim myProcesses() As Process 'Funny - withouth the () in the myProcesses it does not work...
6
1891
by: Roger Heathcote | last post by:
sjdevnull@yahoo.com wrote: <snip> Fair point, but for sub processes that need to be in close contact with the original app, or very small functions that you'd like 100s or 1000s of it seems...
3
2377
by: eeriehunk | last post by:
Hi All, I am a little confused between a session and a process. I learnt that an Oracle Session is created for every login. And we can run many processes in one session. I have also learnt how to...
0
6908
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...
0
7081
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6737
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...
0
6921
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...
0
5336
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4776
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4481
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...
0
2984
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
179
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...

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.