Messages in this thread | | | Subject | Re: Schedule idle | From | (Dale E. Martin) | Date | 10 Nov 1998 01:08:14 -0500 |
| |
Harald Koenig <koenig@tat.physik.uni-tuebingen.de> writes:
> if there is another solution which will claim only some very few % of CPU-time > for those background/idle jobs (vs. nice-19 tasks) I'd be happy to use it...
A buddy of mine wrote "loadwatch" specifically for rc5. Invoke it like this, (on a uni-CPU machine): loadwatch -d 15 -h 1.25 -l 0.25 -- ./rc5des
[ begin included program ]
/* as is, etc. */
#include <stdio.h> #include <unistd.h> #include <stdlib.h> #include <signal.h> #include <sys/types.h> #include <string.h> #include <time.h> #include <sys/wait.h> #include <signal.h>
main(int argc, char **argv) { int delay = 60; float highmark = 3.0; float lowmark = 2.0; int c; pid_t child; pid_t childgroup;
while ((c = getopt(argc, argv, "d:l:h:")) != -1) { switch (c) { case 'd': delay = atoi(optarg); break;
case 'h': highmark = atof(optarg); break;
case 'l': lowmark = atof(optarg); break; default: fprintf(stderr, "unknown option '%c'\n", c); exit(1); } }
if ((child = fork()) == 0) { setpgrp(); execv(argv[optind], argv + optind); } else { FILE *file; double one, ten, fifteen; int state = 0; char line[80]; char *outline; pid_t status; sleep(1); childgroup = getpgid(child); while (1) { time_t now = time(0); outline = ctime(&now); *(strchr(outline, '\n')) = 0;
switch (status = waitpid(child, 0, WNOHANG)) { case -1: perror("problems waiting for child"); kill(-childgroup, SIGTERM); exit(1); break;
case 0: break;
default: fprintf(stderr, "%s: no child process, exiting.\n", outline); exit(0); break; } one = ten = fifteen = 0.0; file = fopen("/proc/loadavg", "r"); if (fgets(line, 80, file)) { one = atof(line); if (state == 0 && one >= highmark) { fprintf(stderr, "%s: load to high, stopping.\n", outline); state = 1; kill(-childgroup, SIGSTOP); } else if (state == 1 && one <= lowmark) { fprintf(stderr, "%s: load low, continuing.\n", outline); state = 0; kill(-childgroup, SIGCONT); } } fclose(file); sleep(delay); } } }
-- +-------------------- finger for pgp public key ---------------------+ | Dale E. Martin | Clifton Labs, Inc. | Senior Computer Engineer | | dmartin@clifton-labs.com | http://www.clifton-labs.com | +----------------------------------------------------------------------+
- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu Please read the FAQ at http://www.tux.org/lkml/
| |