/* RT user. Copyright (c) 2002 Roger Larsson This program is free software; you can redistribute it and/or modify it under the terms of version 2 of the GNU General Public License as published by the Free Software Foundation. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. Thanks to autor of KSysGuard Chris Schlaeger for borrowed code... */ #include #include #include #include #include #include struct request { pid_t pid; char _filler[32]; }; int main(int argc, char *argv[]) { struct request request; FILE *reqf; int done=0, loops = 0; request.pid = getpid(); while (!done) { switch (getopt(argc, argv, "?c:p:" )) { case 'c': loops = atoi(optarg); break; case 'p': request.pid = atoi(optarg); printf("pid %d\n", request.pid); break; case '?': printf("%s: [-c|-p pid]\n", argv[0]); printf("\t-c loops\tcheck monitor function by looping\n"); printf("\t-p pid\trequest on behalf of other process\n"); return 1; case -1: // No more options done = 1; break; } } printf("As long as no monitor runs, execution will sleep here...\n"); reqf = fopen("/var/named/rt-request", "w"); if (reqf == NULL) { perror("fopen"); return errno; } printf("policy %d\n", sched_getscheduler(request.pid)); fwrite(&request, 32, 1, reqf); fclose(reqf); // important! (maybe flush?) printf("policy %d\n", sched_getscheduler(request.pid)); // well behaved if (request.pid == getpid() && loops > 0) { // Wait until RT prio raised while (sched_getscheduler(request.pid) == 0) { } printf("\nsleep for 3 seconds then start with a\n"); printf("busy wait for %d loops (or until prio reduced)\n", loops); printf(" move your mouse!\n"); sleep(3); while (--loops > 0 && sched_getscheduler(request.pid) != 0) { // someone did listen to my request... // assume monitor is running } if (loops == 0) printf(" - normal loop finish, to short loop?\n"); else printf(" - monitor works! (priority got reduced)\n"); } return 0; }