Solved

How to pause  a program

Posted on 2001-06-24
24
186 Views
Last Modified: 2010-04-02
My program launches several other programs.
I'm looking for a good way to pause these programs, and then un-pause them.
0
Comment
Question by:Kisses93834
  • 10
  • 8
  • 6
24 Comments
 
LVL 22

Expert Comment

by:nietod
ID: 6222817
In standand C++ there is no way to do this.   This woudl have to be done using some OS-specific mechanism.  But you have not stated your OS, so we can't provide a definite answer.

If this is for windows, you can use CreateProcess() to create the secondary processes, this will allow you to get handles to the those processes primary threads and you can then suspend them with SuspendThread().

Now if the secondary processes crate multiple threads, this won't work as only the primary thread will be suspended.  in that case, you will have to develope some system for communicating with the other processes and design them to suspend cooperatively.  For example, you coudl use an event object (CreateEvent()) to signal when the processes shoudl run and when they should suspend.  

Note that you probably don't want to suspend a process for more than about a second at a time.  (Unless it is either a console or non-interactive process) as it won't respond to the user and could cause confusssion.  If this is for a GUI process and you need to interact with the user, you might be forced to reconsider.  you might not want to really suspend the pocess completely, only suspend one or two tasks it performs and allow other tasks to contineu so it is interactive.  Again  this will probably require some sort of coooperative system and the use of soem form of interprocess communication.

If you provide more details, I can be more specific.
0
 
LVL 30

Expert Comment

by:Axter
ID: 6222866
Check out the following link:
http://www.axter.com/faq/topic.asp?TOPIC_ID=24&FORUM_ID=4&CAT_ID=9&Topic_Title=How+to+launch+a+program+from+another+program+in+VC&Forum_Title=C%2FC%2B%2B

It has a class called CreateProcessMngr.  This class can let you easily start and pause a program.  Also lets you kill it easy.
0
 

Author Comment

by:Kisses93834
ID: 6223190
It's for windows, but I'm launching DOS and windows programs.
0
 

Author Comment

by:Kisses93834
ID: 6223197
Axter,
How would I use that class?
0
 
LVL 30

Accepted Solution

by:
Axter earned 200 total points
ID: 6223342
CreateProcessMngr cp("E:\\Borland\\TC\\Bin\\tc.exe","E:\\Borland\\TC\\Bin\\",NULL,NULL,SW_NORMAL);
cp.SuspendThread();

//.............code here

cp.ResumeThread();
0
 

Author Comment

by:Kisses93834
ID: 6223395
I'll give it a try.
0
 
LVL 22

Expert Comment

by:nietod
ID: 6224060
How does the class work?   I assume it doesn't use CreateProcess() and SuspendThread().
0
 

Author Comment

by:Kisses93834
ID: 6225825
That worked good.  Thanks
0
 
LVL 22

Expert Comment

by:nietod
ID: 6225950
I'm sort of curious how it works?

Obviosuly it doesn't use the techniques I suggested, Axter would have said so, but I can't image what is left....
0
 
LVL 30

Expert Comment

by:Axter
ID: 6230960
Kisses93834,
In your original code, were you using CreateProcess() function?

Did you use any information in nietod comment for your solution?

nietod comment's has a general description of what the wrapper class does, and he is upset because I did not point this out to you.

So I'm pointing it out to you know, and I would like to know if I had pointed this out before, would it had made any difference as to who you would have awarded the points to?

Thank you
0
 
LVL 22

Expert Comment

by:nietod
ID: 6230966
its not a matter of points.  Its a matter of etiquette.
0
 
LVL 30

Expert Comment

by:Axter
ID: 6230996
To tell you the truth, I did not bother to read your very lengthy comment.  To much stuff.
You can not plagerism something that you have not read.
If your comment was shorter and to the point, maybe I would have picked up on it.
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 

Author Comment

by:Kisses93834
ID: 6231035
I was useing the CreateProcess function in my original code.

I did not understand nietod's comment.

I thought he was going to give me additional information after I told him what was my OS.  but he did not.

No, it would not have made a difference as to who I would have awarded the points to.

Was I supposed to awarded to nietod?
0
 
LVL 22

Expert Comment

by:nietod
ID: 6231135
>>  thought he was going to give me additional information after I told
>> him what was my OS.  but he did not.

I would have, but you accepted Axter's comment.

>> Was I supposed to awarded to nietod?
That is up to you.  

The point is that Axter's solution used the very same techniques I had suggested.  He didn't point this out.  Many clients would thus choose to give the points to me--but not necesesarily.  But in any case it is still propper to point this out.
0
 
LVL 30

Expert Comment

by:Axter
ID: 6231781
Well I hope your satisfied.  It's been pointed out, and this matter should be closed.
0
 
LVL 22

Expert Comment

by:nietod
ID: 6231940
And in the future?
0
 
LVL 30

Expert Comment

by:Axter
ID: 6232038
>>And in the future?
I will make sure to the best of my ability to give you your kodoos.  And if your comment is to long for me to read, then I'll just put a disclaimer on my posted comment.
Something like:
"This may or may not be part of oh mighty nietod the magnificent previous posted solution."
0
 
LVL 22

Expert Comment

by:nietod
ID: 6232319
But you'd plagerize from others?

If you can't bother to read the entire question--including its , you should probably stay out of it.  There may be important stuff in there.  Otherwise its like coming into the middle of a conversation.
0
 
LVL 30

Expert Comment

by:Axter
ID: 6232400
You are completely miss using the word plagerizem, and it's obvious you have no idea of what it really means.
0
 
LVL 30

Expert Comment

by:Axter
ID: 6232405
And you are the first, and only person who's ever even suggested that I used their comment as part of my solution.
0
 
LVL 22

Expert Comment

by:nietod
ID: 6232496
>>you have no idea of what it really means.
How many cases of plagerism have you had to decide?

I've been forced to deal with 3.  Not much fun I can tell you.  I don't take it lightly and I assure you that if I didn't understand plagerism--en depth--I would not have been allowed to decude such cases.

>> you are the first, and only person who's ever even suggested that I
>> used their comment as part of my solution.
they perhaps you take the time to read other poeple's comments.   I am certanly not the only one that feels that this is important.  As you've seen today in at least two different questions.
0
 
LVL 30

Expert Comment

by:Axter
ID: 6237927
Kisses93834,
You might be interested in looking at the following link:
http://www.experts-exchange.com/jsp/qShow.jsp?ta=cplusprog&qid=20142416

It's strange how nietod has accuse me of plagerism here, but in the same exact circumstance in the above link, he thinks it's not plagerism.
0
 
LVL 30

Expert Comment

by:Axter
ID: 6237936
He further goes on to post the following comment in another question:
//***********************************************
From nietod:
Don't accuse me of plagerism just to harrass me.  I take it very seriously.  Peoples careers end over
it.  Students are expelled over it.  Its not just some meaningless word to me or to many others.  If
you really think I'm guilty of it, then post a question for CS to handle the matter.   Otherwise, if
its just to harrass me you might consider just how serious a harrassment it is.  Would you taunt a holocaust
survivior by calling them a Nazi, a vietnam vet by calling them a "gook"?   These words have serious
meaning to some individuals.
//***********************************************

Seems like it's alright for him to accuse me of plagerism, but all of the sudden, it's a serious offense, when I do the same to him.
0
 

Author Comment

by:Kisses93834
ID: 6237987
Axter,
After reading nietod's last comment I decided to ignore him.  Now that I have briefly read the above link, and the above comment, it has validated my previous decision.
I suggest that you do the same.  Just ignore him.
0

Featured Post

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

Join & Write a Comment

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

746 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

12 Experts available now in Live!

Get 1:1 Help Now