|
setlinuxpri.c C-Language Source Code
/* Set a process to a constant and permanent priority
Name: setlinuxpri.c
Compile using: gcc -o setlinuxpri setlinuxpri.c
chown root setlinuxpri
chmod 0500 setlinuxpri
Usage: setlinuxpri -p ProcessID -P Priority
*/
#include
#include
int setpriority(int which, id_t who, int value);
int getopt (ArgumentC, ArgumentV, OptionString);
int ArgumentC;
char *const ArgumentV [ ];
const char *OptionString;
extern int optind;
extern int optopt;
extern int opterr;
extern char * optarg;
/* ############################################################# */
int main(int argc, char** argv)
{
int arg;
int ProcessID;
int Priority;
int out;
ProcessID = -1;
Priority = 60;
while (arg!=EOF)
{
arg=getopt(argc, argv, "p:P:");
switch(arg)
{
/* Set the process id number */
case 'p':
ProcessID=atoi(optarg);
break;
/* Set the priority number */
case 'P':
Priority=atoi(optarg); /* Set the priority */
break;
case '?':
exit(usage());
}
}
if ( ProcessID >= 0 ) {
out = setpriority ( PRIO_PROCESS, ProcessID, Priority);
} else {
printf("setlinuxpri: -p option is required\n");
exit(usage());
}
}
/* ################################################################ */
/* usage */
int usage()
{
printf("\nSyntax: setlinuxpri -p ProcessID [-P Priority]\n");
printf(" Maximum Priority = 1\n");
printf(" Default Priority = 60\n");
printf(" Minimum Priority = 254\n");
return(1);
}
|
|
|