5

I want to do a large disk transfer, which slows down responsiveness of my system.

What I want is a Unix command that will only run the command after I have been idle at the console for a few minutes. And if I come back half way in, it will suspend the job. Until I walk away from my computer.

Is there such a command, or software package?

[edit: The key part of this question is how to determine if there is console activity, to automatically suspend.]

Joseph Turian
  • 265
  • 2
  • 7

5 Answers5

4

You can achieve this by first getting the process PID with:

ps aux | grep <process_name>

write down the PID (it's the second column), then suspend it with:

kill -STOP <pid>

and continue it with:

kill -CONT <pid>
mdeous
  • 378
  • 3
  • 11
2

How about just running the command normally, and then using "nice" on it to lower its priority?

Alex
  • 253
  • 2
  • 9
  • http://linux.die.net/man/1/nice – Zoredache Mar 16 '10 at 17:51
  • 2
    You'll probably want to use 'ionice' if it's disk bound, rather than 'nice' – James Mar 16 '10 at 18:55
  • 1
    'nice' has almost no affect. 'ionice' mostly works, but even at the "nicest" value, heavy I/O will noticeably slow down other processes. The only reliable solution I have found for this is pausing the processes occasionally to let the I/O load settle. – Mark Porter Mar 16 '10 at 19:03
2

I once wrote a "pause_io" script that would accept a number and then pgrep all the types of things that are likely to whomp my IO, e.g. rsync, updatedb, and cp. Then it would kill -STOP those pids and sleep for the supplied number of minutes and then kill -CONT each of them. When I needed responsive access to the box I would execute

    pause_io 10 &

And I would have 10 minutes without heavy I/O

It went something like this:

    #!/bin/bash

    TIMEOUT=$(($1*60))
    TASKS="mlocate|updatedb|rsync|cp"

    pkill $TASKS -signal STOP
    sleep $TIMEOUT
    pkill $TASKS -signal CONT
Mark Porter
  • 991
  • 1
  • 5
  • 12
0

rsync has a --bwlimit option.

Dennis Williamson
  • 60,515
  • 14
  • 113
  • 148
  • be aware the the "bwlimit" only affects file transfer, not the file analysis. If you are analyzing something big, like for mirroring or backups, then the analysis I/O can be worse than the file transfer I/O – Mark Porter Mar 16 '10 at 19:00
0

Run the suggested -STOP and -CONT as part of some screen-saver maybe?

(If you're on a terminal: There's also a screen-saver for terminals, but I don't know its name, or where to set its options. All I know is, that it's on by default on Ubuntu :-)

Chris Lercher
  • 3,982
  • 9
  • 34
  • 41