by michaelcampbell · 3y ago · 0 comments
for i in list_of_files; do
run_intensive_process &
sleep $(awk '{print $3}' < /proc/loadavg)
done
As more processes start upping my load average, it sleeps longer before running each one in the background. I guess GNU parallel can do this sort of thing with a load-sensitive command line arg, but I find this pattern easy to remember, and parallel's decidedly not.Works for me.
https://linux.die.net/man/1/at
I don't think at is very heavily used on modern systems, so it's quite possible that it doesn't actually have very useful behaviour here.
at(1) runs jobs after a specified time. (A common mistake is to presume that "at" means "will run when specified" when in fact it means "will run no earlier than specified", and depending on system characteristics, could run substantially later.)
batch runs jobs ... as system load permits, without any time specification, in a FIFO queue.
There's also cron, the third Unix scheduler, which executes a set of specified tasks on a regular schedule. All three are related.
As far as I know, cron doesn't pay attention to load average, but I would love to be corrected.
All of this feels like a very crufty and highly neglected part of Unix, which is a shame. There's an alternate history of Unix where it's all about batch jobs and datagram Unix domain sockets.
It does not. Up to whatever you run from cron to deal with that.
On many systems they'll share an integrated manpage.
cat list_of_file | parallel --load 100% run_intensive_process