You can pause execution of a process by sending it a SIGSTOP
signal and then later resume it by sending it a SIGCONT
.
Assuming your workload is a single process (doesn't fork helpers running in background), you can use something like this:
# start copy in background, store pid
cp src dst &
echo "$!" >/var/run/bigcopy.pid
Then when busy time starts, send it a SIGSTOP
:
# pause execution of bigcopy
kill -STOP "$(cat /var/run/bigcopy.pid)"
Later on, when the server is idle again, resume it.
# resume execution of bigcopy
kill -CONT "$(cat /var/run/bigcopy.pid)"
You will need to schedule this for specific times when you want it executed, you can use tools such as cron or systemd timers (or a variety of other similar tools) to get this scheduled. Instead of scheduling based on a time interval, you might choose to monitor the server (perhaps looking at load average, CPU usage or activity from server logs) to make a decision of when to pause/resume the copy.
You also need to manage the PID file (if you use one), make sure your copy is actually still running before pausing it, probably you'll want to clean up by removing the PID file once the copy is finished, etc.
In other words, you need more around this to make a reliable, but the base idea of using these SIGSTOP
and SIGCONT
signals to pause/resume execution of a process seems to be what you're looking for.
cp -al
to make a hardlink farm? Or use a filesystem that supports block-level reflinks with copy-on-write, usingcp -a --reflink=auto
? BTRFS and ZFS support that for copies within the same physical device.src
change between 9:00 and 14:00? If so, simply pausing and resuming thecp
process may result in corrupted files. It may be better to runrsync
in combination with thetimeout
command.