Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Suspend job and resume automatically later [solved]
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo
View previous topic :: View next topic  
Author Message
BarryJ
n00b
n00b


Joined: 13 Apr 2003
Posts: 72
Location: Wisconsin, USA

PostPosted: Sat Apr 10, 2004 3:25 am    Post subject: Suspend job and resume automatically later [solved] Reply with quote

Is it possible (maybe with some command or some program to emerge) to pause a task (much like hitting Ctrl+Z) and then have it automatically resume (like then typing fg) at some time (like midnight, or 2 hours after it's paused)? Nothing will actually be running on that particular console at that time, but the task that needs to be paused uses 100% of the CPU and I need to do something more important, but I won't be around to resume the first task. Anyone know of a way?

Last edited by BarryJ on Sat Apr 10, 2004 5:23 am; edited 1 time in total
Back to top
View user's profile Send private message
TimG
n00b
n00b


Joined: 03 Jun 2003
Posts: 62
Location: Houston, TX

PostPosted: Sat Apr 10, 2004 4:48 am    Post subject: Reply with quote

use Ctrl+Z to suspend your process

Code:
sleep 2h;fg


in 2 hours, it will execute the fg command so you have 2 hours of your proc not being used.

sleep also accepts s for seconds, d for days and m for minutes
Back to top
View user's profile Send private message
BarryJ
n00b
n00b


Joined: 13 Apr 2003
Posts: 72
Location: Wisconsin, USA

PostPosted: Sat Apr 10, 2004 5:22 am    Post subject: Reply with quote

Awesome! Thank you!
Back to top
View user's profile Send private message
natrik
n00b
n00b


Joined: 05 Jun 2006
Posts: 4

PostPosted: Mon Jun 05, 2006 4:11 am    Post subject: Nice is also good Reply with quote

If it's just a CPU intensive task, and the reason you need to pause it is to free up CPU time, then maybe consider starting it with `nice` ... that will reduce the priority of the heavy task so that the rest of the system remains responsive. The heavy task will continue to use *almost* as much of the CPU (it won't really slow it down by much) but it will be scheduled in such a way as to not interfere with your interactive processes.

nice "cpu-hog-binary --options"

I often use it in conjunction with `time` when I'm feeling nosey to see how much time a heavy task spends on the cpu (and how much elapsed time it takes).

time nice "cpu-hog-binary --options"

It should be noted that many shells (tcsh, at least, and probably bash) have their own internal 'nice' and 'time' commands which don't execute the binaries /usr/bin/nice or /usr/bin/time. ... so if you want specifically to call those programs, use their full path. See the manpages for details.

I hope this might be a more elegant solution than pausing your heavy task completely. Of course, if your task is hogging other resources like network or disk in addition to the CPU, then `nice` probably is less helpful than a full on pause.

-- Nate

PS: I don't mean to say the sleep method is inelegant ... I rather like it :o)
Back to top
View user's profile Send private message
midnightlightning
Tux's lil' helper
Tux's lil' helper


Joined: 19 Dec 2004
Posts: 79

PostPosted: Mon Jun 05, 2006 6:37 pm    Post subject: Reply with quote

TimG wrote:
use Ctrl+Z to suspend your process

Code:
sleep 2h;fg


in 2 hours, it will execute the fg command so you have 2 hours of your proc not being used.

Won't you also need to put a '&' on the end of that sleep command, since as written, it will not give you back your command line until 2 hours from now after it runs fg. So I think you either need to do:
Code:
Ctrl+Z out of hog
$ sleep 2h && fg &
[1] 1610
$ commands-I-really-wanted-to-run-but-hog-was-hogging-my-CPU
$

and just walk away, the fg will run after 2 hours. Or,
Code:
Ctrl+Z out of hog
$ commands-I-really-wanted-to-run-but-hog-was-hogging-my-CPU &
$ sleep 2h; fg
... (two hour delay) ...
$

The first option is good if the reason you want the time delayed start is because the process you want to run won't get you back to a command line while running (it's not a background-able task?), so you can start the timer on fg before starting. If your alternate process doesn't need attending, you can send it to the background too, while processing and then execute the sleep command, which will tie up your command line while it waits.
_________________
"Any sufficiently advanced technology is indistinguisable from magic." -- Arthur C. Clarke
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum