--- make-4.2.1/job.c 2016-05-21 21:22:32.000000000 +0100 +++ make-4.2.1.1/job.c 2016-10-09 19:12:07.425523927 +0100 @@ -1925,10 +1925,60 @@ static int load_too_high (void) { #if defined(__MSDOS__) || defined(VMS) || defined(_AMIGA) || defined(__riscos__) return 1; +#elif defined(HAVE_PROC_LOADAVG) + /* Read from /proc/loadavg and use the number of active running + tasks & threads to determine if we can start another process. */ +#define PROC_LOADAVG_SIZE 64 + static int fd = -2; + char proc_loadavg[PROC_LOADAVG_SIZE]; + int i, p; + + if (max_load_average < 0) + return 0; + + if (fd == -2) + { + fd = open ("/proc/loadavg", O_RDONLY); + if (fd < 0) + { + perror_with_name (_("cannot open /proc/loadavg: "), "open"); + fd = -1; + return 0; + } + } + if (read (fd, proc_loadavg, PROC_LOADAVG_SIZE) < 0) + { + perror_with_name (_("cannot read /proc/loadavg: "), "read"); + close(fd); + fd = -1; + return 0; + } + if (lseek (fd, 0, SEEK_SET) < 0) + { + perror_with_name (_("cannot seek on /proc/loadavg: "), "lseek"); + close(fd); + fd = -1; + return 0; + } + proc_loadavg[PROC_LOADAVG_SIZE-1] = '\0'; + for (i = p = 0; i < 3 && p < PROC_LOADAVG_SIZE; ++p) + { + if (proc_loadavg[p] == ' ') + ++i; + } + if (i < 3) + { + errno = ENOTSUP; + perror_with_name (_("unsupported format of /proc/loadavg: "), "load_too_high"); + close (fd); + fd = -1; + return 0; + } + return max_load_average < (double) atoi (&proc_loadavg[p]); #else static double last_sec; static time_t last_now; double load, guess; time_t now;