LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-11-2016, 09:04 AM   #1
knobby67
Member
 
Registered: Mar 2006
Posts: 622

Rep: Reputation: 42
Pausing and un-pausing programs from a master program using kill


Hi All,
I'm running a master program that in turn runs other hi res graphics demos. Basically this master system is used as it takes 45 secs + to load in each demo. So rather than load each demo each time, I load in a demo, pause it, load in the next. When they are all loaded in the master program loops allowing the user to select a demo, when they select the master is paused and the demo is unpaused.
This appears to work at first however every so often, sometimes after a few tries sometimes after a long long time it locks up. I think the pause unpause of processes are not syncing, multi core issue? So my code flow is, start the master program

Code:
load in demo 1.  When it's loaded unpause master
pause master.
load in demo N   When it's loaded unpause master 
pause master


do
user selects demo so it's unpaused -> in demo user can exit which pauses demo and unpauses master.   
pause master
while
I'm using kill from system calls to pause unpause eg
Code:
void ProcessControl_Class::pause_local_process( void )
{
std::string command = "kill -STOP ";
command += std::to_string( process_id );

system( command.c_str( ) );

}

void ProcessControl_Class::unpause_external_process( std::string process )
{
std::string command = "kill -CONT ";
command += std::to_string( get_external_process_id( process ) );

system( command.c_str( ) );

}
I've been reading last night and came across the following functions waitpid() execl(), I was thinking of trying these, but they seem to be used only with forked child processors. So I'm a bit confused. Can I used these to replace the kill -STOP -CONT and system("./demo")?;
 
Old 01-11-2016, 01:55 PM   #2
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 9,078
Blog Entries: 4

Rep: Reputation: 3184Reputation: 3184Reputation: 3184Reputation: 3184Reputation: 3184Reputation: 3184Reputation: 3184Reputation: 3184Reputation: 3184Reputation: 3184Reputation: 3184
I suggest that, rather than trying to freeze the threads/processes "externally" ... which would leave them in an uncertain state ... you should design them so that they expect to receive signals, say SIGUSR1 and SIGUSR2, which would mean "please pause" and "please resume," respectively.

Upon receipt of the appropriate signal, the processes would enter or leave a "paused" state ... whatever such a thing means to them ... and, most importantly, they would be the ones doing it. They continue to be alive-and-well, and they continue to be masters of their own affairs.

I envision that perhaps each program has a "state" variable which might include such states as (RUNNING, PAUSING, PAUSED, RESUMING), and a condition-variable upon which the process can "hard wait" while PAUSED. (The variable is signaled by the SIGUSR2 handler.) So, the process would "fall deeply asleep" while waiting to be continued, but it would handle all state-transitions cleanly and on its own terms.
 
2 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Pausing a process sidharth.nitj Programming 1 06-15-2007 02:33 AM
Pausing the screen JStew Programming 8 02-27-2007 09:47 AM
Pausing the execution of a java program with linux balteo Linux - Software 2 09-04-2005 11:47 AM
Pausing a program kamransoomro84 Linux - General 0 05-08-2004 05:25 PM
Pausing downloads KptnKrill Linux - Newbie 3 07-28-2003 10:30 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:19 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration