/* * runon.c - assign a process to a named processor * * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved. * * 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 would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * Further, this software is distributed without any warranty that it is * free of the rightful claim of any third person regarding infringement * or the like. Any license provided herein, whether implied or * otherwise, applies only to this software file. Patent licenses, if * any, provided herein do not apply to combinations of this program with * other software, or any other product whatsoever. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy, * Mountain View, CA 94043, or: * * http://www.sgi.com * * For further information regarding this notice, see: * * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/ */ #include #include #include #define _POSIX_OPTION_ORDER static void usage(); int main(argc, argv) int argc; char *argv[]; { extern errno; extern __const char *__const sys_errlist[]; int c, processor, pid; int usepid = 0; register char *p; if (argc < 3) { usage(); exit(1); } while ((c = getopt (argc, argv, "p:")) != -1) { switch(c) { case 'p': usepid = 1; pid = atoi(optarg); break; } } p = argv[optind]; while(*p) { if(!isdigit(*p)) { fprintf(stderr, "%s: cpu argument must be numeric.\n", argv[0]); exit(2); } p++; } processor = atoi(&argv[optind][0]); optind++; if (usepid) { if (prctl(PR_MUSTRUN_PID, processor, pid, 0, 0) < 0) { fprintf(stderr, "%s: could not attach pid %d to processor %d\n", argv[0], pid, processor); exit(1); } } else { if (prctl(PR_SET_RUNON, processor, 0, 0, 0) < 0) { fprintf(stderr, "%s: could not attach to processor %d -- %s\n ", argv[0], processor, sys_errlist[errno]); exit(1); } execvp(argv[optind], &argv[optind]); fprintf(stderr, "%s: %s\n", sys_errlist[errno], argv[optind]); exit(1); } return(0); } static void usage() { fprintf(stderr, "usage: runon processor (-p pid | command [args...])\n"); }