2
This file is part of GNUnet
3
(C) 2002, 2003, 2004, 2005, 2006 Christian Grothoff (and other contributing authors)
5
GNUnet is free software; you can redistribute it and/or modify
6
it under the terms of the GNU General Public License as published
7
by the Free Software Foundation; either version 2, or (at your
8
option) any later version.
10
GNUnet is distributed in the hope that it will be useful, but
11
WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
General Public License for more details.
15
You should have received a copy of the GNU General Public License
16
along with GNUnet; see the file COPYING. If not, write to the
17
Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18
Boston, MA 02111-1307, USA.
22
* @file util/os/priority.c
23
* @brief Methods to set process priority
28
#include "gnunet_util_error.h"
29
#include "gnunet_util_os.h"
32
* Set our process priority
35
GNUNET_set_process_priority (struct GNUNET_GE_Context *ectx, const char *str)
39
GNUNET_GE_ASSERT (ectx, str != NULL);
40
/* We support four levels (NORMAL, ABOVE NORMAL, BELOW NORMAL, HIGH and IDLE)
41
* and the usual numeric nice() increments */
42
if (strcmp (str, "NORMAL") == 0)
44
prio = NORMAL_PRIORITY_CLASS;
48
else if (strcmp (str, "ABOVE NORMAL") == 0)
50
prio = ABOVE_NORMAL_PRIORITY_CLASS;
54
else if (strcmp (str, "BELOW NORMAL") == 0)
56
prio = BELOW_NORMAL_PRIORITY_CLASS;
60
else if (strcmp (str, "HIGH") == 0)
62
prio = HIGH_PRIORITY_CLASS;
66
else if (strcmp (str, "IDLE") == 0)
68
prio = IDLE_PRIORITY_CLASS;
74
if (1 != sscanf (str, "%d", &prio))
77
GNUNET_GE_USER | GNUNET_GE_BULK | GNUNET_GE_ERROR,
78
_("Invalid process priority `%s'\n"), str);
83
/* Convert the nice increment to a priority class */
85
prio = NORMAL_PRIORITY_CLASS;
86
else if (prio > 0 && prio <= 10)
87
prio = BELOW_NORMAL_PRIORITY_CLASS;
89
prio = IDLE_PRIORITY_CLASS;
90
else if (prio < 0 && prio >= -10)
91
prio = ABOVE_NORMAL_PRIORITY_CLASS;
93
prio = HIGH_PRIORITY_CLASS;
97
/* Set process priority */
99
SetPriorityClass (GetCurrentProcess (), prio);
105
GNUNET_GE_LOG_STRERROR (ectx,
106
GNUNET_GE_WARNING | GNUNET_GE_ADMIN |
107
GNUNET_GE_BULK, "nice");
108
return GNUNET_SYSERR;