Hi all :))
I'm resending this message, this time with the source code
attached, just in case you want to use it. I won't bother you again
with this issue ;))
I've noticed that GNU coreutils doesn't include a 'renice'
command, which is in the Single Unix Specification (don't know if it
is in the POSIX standard). Well, the matter is that I wrote a
'renice' command, SuS compliant I think, a time ago, and it's GPL'd,
although not released yet (it is part of a whole).
If you want the source for including a renice command in
coreutils, just tell. It's small and (hopefully) bug free. I can
maintain the documentation if you want me to. The code is another
issue. I don't code according to GNU standards and I will not, nor
make the code multilingual, etc... I can fix bugs, even maintain the
code once it is converted to GNU standards, but I won't convert it,
sorry O:))) Don't take it bad.
Thanks for coreutils, I'm impatient for seeing the first stable
release, go on :))
Ra�l
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>
#include <limits.h>
#include <pwd.h>
#include <sys/resource.h>
//#include "die.h"
/*
* Change the priority (nice) of processes
* or groups of processes which are already
* running.
*/
char idstring[]="renice 2.0b";
int main(int argc, char *argv[]) {
int class=PRIO_PROCESS; /* Class to renice. Processes by default */
int id=0; /* PID, PGID or UID to renice. '0' is invalid. */
int newnice=0; /* New nice value (priority). */
if (argc < 2) {
fprintf(stderr, "%s\n\n", idstring);
fprintf(stderr,
"Usage: %s NEWNICE [-p|-g|-u] WHAT...\n", argv[0]);
fputs("Sets nice value of each WHAT to NEWNICE.\n\n",
stderr);
fputs(" -p following WHATs are PIDs (default).\n",
stderr);
fputs(" -g following WHATs are PGIDs.\n",
stderr);
fputs(" -u following WHATs are UID or user names.\n",
stderr);
exit(EXIT_FAILURE);
} else { /* Get the new nice value right here :))) */
char *error=NULL;
errno=0; /* So we can catch errors in 'strtol'*/
/* Get rid of program name */
argv++, argc--;
newnice=strtol(*argv, &error, 10);
if ((newnice==0) && (*error)) /* Invalid number... */
die("Invalid priority `%s'", *argv);
if ((errno==ERANGE)
|| (newnice > PRIO_MAX)
|| (newnice < PRIO_MIN))
die("Priority `%s' out of range [%d,%d]",
*argv, PRIO_MIN, PRIO_MAX);
argv++, argc--; /* Get the rest of parameters */
}
while(argc--) {
if (**argv=='-') { /* Class change requested... */
if (!strcmp(*argv, "-p")) {
class=PRIO_PROCESS;
} else if (!strcmp(*argv, "-g")) {
class=PRIO_PGRP;
} else if (!strcmp(*argv, "-u")) {
class=PRIO_USER;
} else die("%s: Invalid WHAT class `%s'", *argv);
if (argc) {
argv++;
continue;
} else die("Missing ID for class `%s'", *argv);
} else if (class==PRIO_USER) { /* It can be an username */
struct passwd *pwdentry=getpwnam(*argv);
if (pwdentry)
id=pwdentry->pw_uid;
else die("Invalid username `%s'", *argv);
} else {
char *error=NULL;
unsigned long tmpid=0; /* For avoiding overflows */
errno=0;
tmpid=strtoul(*argv, &error, 10);
if ((tmpid==0) && (*error)) /* Bad value */
die("Invalid ID `%s'", *argv);
if ((errno==ERANGE) || /* Out of range */
(tmpid > INT_MAX) ||
(tmpid <= 0))
die("ID `%s' out of range [1,%d]",
*argv, INT_MAX);
id=tmpid; /* If we are here, all went well :) */
}
argv++;
/*
Do the renice. First, let's use 'getpriority' to validate
CLASS & ID combination.
*/
errno=0;
if ((getpriority(class, id)==-1) && errno)
die("Cannot get priority");
else if (setpriority(class, id, newnice)==-1)
die("Cannot set priority");
switch(class) {
case PRIO_PGRP:
fprintf(stdout, "Process group `%d'", id);
break;
case PRIO_PROCESS:
fprintf(stdout, "Process `%d'", id);
break;
case PRIO_USER:
fprintf(stdout, "User `%d'(%s)",
id, (getpwuid(id))->pw_name);
break;
}
fprintf(stdout," reniced to priority `%d'\n", newnice);
}
return EXIT_SUCCESS;
}
_______________________________________________
Bug-coreutils mailing list
[EMAIL PROTECTED]
http://mail.gnu.org/mailman/listinfo/bug-coreutils