Go Back > Extra Stuff > Linux

Thread Tools
Old 2016-01-29, 15:48   #1
Xyzzy's Avatar
Aug 2002

3·7·389 Posts
Default Pausing/resuming a process automatically?

We have msieve running on our low-powered NUC, which has an i5 processor with two real cores and two HT cores. The NUC has 16GiB of RAM.

If we run msieve using both real cores, our web browsing becomes unbearably slow. We suspect the onboard video which uses shared (system) memory is the culprit. (Other programs seem to work fine.)

If we run msieve on just one core the browser responds reasonably fast. We only use the browser for two or three hours a day so it pains us to use only one core for msieve because that means that the other 21 to 22 hours of the day we are only getting half the work done.

Changing the niceness of msieve does not make a difference. Locking the process to specific cores (taskset) does not make a difference either.

We could manually pause (suspend) the msieve process but then we would probably forget to unpause it when we were done.

Is there a way to trigger the pause/unpause based on a system event? For example, when the DPMS kicks off our monitor would be a good time to resume msieve. And when the monitor turns on would be a good time to suspend msieve.

Xyzzy is offline   Reply With Quote
Old 2016-01-29, 17:35   #2
paulunderwood's Avatar
Sep 2002
Database er0rr

3,677 Posts

Here is how to use jobs, fg, bg, ^z. You could have a cron job that checks for the absence of the browser process and then "bg" to resume msieve?

Last fiddled with by paulunderwood on 2016-01-29 at 17:51
paulunderwood is offline   Reply With Quote
Old 2016-01-30, 00:24   #3
Xyzzy's Avatar
Aug 2002

3·7·389 Posts

We like to keep our browser open (with lots of tabs) so that idea will not work for us.

Mprime has the ability to pause itself. We wonder how hard this feature would be to add to msieve?

In rare cases, users have reported the program can interfere with the
performance of some programs such as disk defragmenters and some games.
You can pause the program automatically when these programs are running by
adding this line to prime.txt:
The [n1], [n2] values are optional and indicate the number of worker threads
to pause when prog1 and prog2 are running.  The default value for n1 and n2
is to pause all worker threads.  Note that the program will pause if the program
name matches any part of the running program's file name.  That is "foobar"
will match "c:\foobar.exe", "C:\FOOBAR\name.exe", and even "C:\myfoobarprog.exe".
Also, if prog1 is "*" the program will pause no matter what.  Examples:
    PauseWhileRunning=*[1] during 6-7/2:00-3:00
    PauseWhileRunning=* during 23:00-24:00 else decomp[1],mygame[2]
The first example pauses one worker thread on Saturday and Sunday between
2AM and 3AM.  The second example pauses all workers between 11PM and 12AM and
pauses 1 worker if decomp is running and 2 if mygame is running.
Xyzzy is offline   Reply With Quote
Old 2016-01-30, 01:17   #4
ewmayer's Avatar
Sep 2002
Rep├║blica de California

11,633 Posts

I'm a fan of low-tech solutions whenever feasible ... if your problem with the simple fg / ctrl-z - to-suspend method is that you forget to 'bg'-resume when done browsing (and the NUCs are so quiet that one can't use fan noise as a reliable subconscious proxy), could you put a CPU-usage display widget at top right or left of your display, with really bright (say, fluorescent-green) %-bars? Then when you minimize your browser the lack of 'color' in the space should remind you to resume your crunching stuff.
ewmayer is offline   Reply With Quote
Old 2016-01-30, 03:02   #5
Dec 2014

3×5×17 Posts

Here is how I solved this once.

Make a new program, like nice(1) and nohup(1), that
takes another command as an argument. Lets call
the new program "pauser" and it has these command
line arguments
pauser [options] command [command arguments]

where options are
-dev <path to /dev file> to check, see below, can be used more than once
-long-sleep <seconds> (default 300)
-short-sleep <seconds> (default 15)

The idea is we can notice user activity by checking the last
modification time on the /dev files for the keyboard and mouse
devices. For example, when I ssh into a machine env variable

when stat(2) says the time on this file has changed, that means
someone has typed something in their ssh session. There are
/dev files for the console and in X windows sessions.

The pauser command works like this
1. start the sub-command and get the PID of it
2. mode = running
3. while <sub command still running>
// When the CPU hog is running, check frequently for user activity
// When the hog is paused, then check less often
4. sleep( mode == running ? short-sleep : long-sleep )
5.a. if mode == running
5.b. stat(2) all the /dev files and if any have changed since the last stat do
5.b.i set mode = paused
5.b.ii send SIGSTOP to our child process using the PID from step 1
5.b.iii continue the while loop
6. if mode == paused
6.a. stat(2) all out /dev files, and if none have changed since last stat do
6.b.i set mode = running
6.b.ii. send SIGCONT to PID
6.b.iii. continue while loop

The basic idea is to check /dev files changing to indicate user activity.
When the CPU hog is running, we check every 15 seconds
and when user activity is noticed, use SIGSTOP to pause the
CPU hog process. Once it is paused, then check every 5 min
for the user inactive and when found, use SIGCONT to restart
the CPU process.

Bonus points for the first one to run this as one command line

nohup pauser nice msieve &
bgbeuning is offline   Reply With Quote
Old 2016-01-31, 02:46   #6
Xyzzy's Avatar
Aug 2002

3×7×389 Posts

After some experimentation today, we found that *not* locking (via taskset) msieve to the physical cores (0-1) allows our browser to run smooth enough to be usable.

Maybe someday we will find (or code) a tool to pause things.

Xyzzy is offline   Reply With Quote
Old 2017-06-22, 19:58   #7
Xyzzy's Avatar
Aug 2002

3·7·389 Posts

Originally Posted by Xyzzy View Post
Maybe someday we will find (or code) a tool to pause things.

Xyzzy is offline   Reply With Quote

Thread Tools

Similar Threads
Thread Thread Starter Forum Replies Last Post
Resuming yafu job (ecm) Johnatan YAFU 4 2016-06-13 11:39
Resuming aliqueit johnadam74 Aliquot Sequences 4 2016-03-28 12:32
Pausing CUDA jobs fivemack Software 0 2013-11-27 23:50
Pausing for games... Xyzzy Software 2 2003-09-25 04:25
Resuming work rc Software 9 2003-02-08 15:08

All times are UTC. The time now is 01:44.

Wed May 19 01:44:31 UTC 2021 up 40 days, 20:25, 0 users, load averages: 1.80, 2.24, 2.19

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2021, Jelsoft Enterprises Ltd.

This forum has received and complied with 0 (zero) government requests for information.

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation.
A copy of the license is included in the FAQ.