[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 203
  • Last Modified:

How to pause a program

My program launches several other programs.
I'm looking for a good way to pause these programs, and then un-pause them.
0
Kisses93834
Asked:
Kisses93834
  • 10
  • 8
  • 6
1 Solution
 
nietodCommented:
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
 
AxterCommented:
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
 
Kisses93834Author Commented:
It's for windows, but I'm launching DOS and windows programs.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Kisses93834Author Commented:
Axter,
How would I use that class?
0
 
AxterCommented:
CreateProcessMngr cp("E:\\Borland\\TC\\Bin\\tc.exe","E:\\Borland\\TC\\Bin\\",NULL,NULL,SW_NORMAL);
cp.SuspendThread();

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

cp.ResumeThread();
0
 
Kisses93834Author Commented:
I'll give it a try.
0
 
nietodCommented:
How does the class work?   I assume it doesn't use CreateProcess() and SuspendThread().
0
 
Kisses93834Author Commented:
That worked good.  Thanks
0
 
nietodCommented:
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
 
AxterCommented:
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
 
nietodCommented:
its not a matter of points.  Its a matter of etiquette.
0
 
AxterCommented:
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
 
Kisses93834Author Commented:
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
 
nietodCommented:
>>  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
 
AxterCommented:
Well I hope your satisfied.  It's been pointed out, and this matter should be closed.
0
 
nietodCommented:
And in the future?
0
 
AxterCommented:
>>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
 
nietodCommented:
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
 
AxterCommented:
You are completely miss using the word plagerizem, and it's obvious you have no idea of what it really means.
0
 
AxterCommented:
And you are the first, and only person who's ever even suggested that I used their comment as part of my solution.
0
 
nietodCommented:
>>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
 
AxterCommented:
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
 
AxterCommented:
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
 
Kisses93834Author Commented:
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 10
  • 8
  • 6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now