I'm a student who wants to benchmark a NGS pipeline, monitoring performance according to how many cores it has allocated to it and the size of the input file. For this reason, I wrote a bash script to call it multiple times with different nr_of_cores parameters and input files, noting down completion time and other stats. The whole thing takes about a day to run through the various scenarios. (Spending, of course, most time on running the biggest file with a single core, so it's not like I'm blocking the whole server for the duration)

I have access to a shared 64-core server to run it on. The shared server, however, varies wildly in number of idle cores depending on time of day and people trying to get projects done. (The top nr_of_cores I'll test is 36, with a small file.)

My question: Is there an easy way to make my bash script wait until it knows [X] cores are available before executing a command? I figure that way, I'd get more reliable data, I wouldn't slow down people with more urgent tasks to run, and I could start the script whenever, instead of waiting until I happen to see with htop that it's a slow day.


  • 3
    There's no job scheduling system, like SLURM, LSF (or other) running that you can use? – Kusalananda Sep 6 '17 at 14:42
  • @Kusalananda: I asked the person who's basically in charge of the server (He's the only lecturer who can scrounge five minutes a week to maintain stuff there) if he knew a good way to do it. No dice. – Elaborate Sep 6 '17 at 20:02
  • 1
    Not as such, because idleness is an instantaneous notion: a core that is idle now might no longer be idle a microsecond later. But you could check the load average, which is more or less a measure of how busy the cores are, and you can get the load average over a period of time. – Gilles 'SO- stop being evil' Sep 6 '17 at 22:24

Assuming that you can afford to tell the system to run it at some later time, and the sysadmin is sensible and has at installed, you can use the following to get it to run when load levels are low enough (zero by default, but the sysadmin can set any arbitrary value for the threshold):

batch << EOF

Other than that though, the only way I know of to do this is to poll the load average yourself and fire off the command when it's below some threshold. If you decide to go that route, what you want to look at is the first field in /proc/loadavg, which gives the 1-minute average.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.