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_common.h"
29 #include "gnunet_os_lib.h"
32 * Set our process priority
35 GNUNET_OS_set_process_priority (pid_t proc,
36 enum GNUNET_SCHEDULER_Priority eprio)
40 GNUNET_assert (eprio < GNUNET_SCHEDULER_PRIORITY_COUNT);
41 if (eprio == GNUNET_SCHEDULER_PRIORITY_KEEP)
43 /* convert to MINGW/Unix values */
46 case GNUNET_SCHEDULER_PRIORITY_DEFAULT:
48 prio = NORMAL_PRIORITY_CLASS;
53 case GNUNET_SCHEDULER_PRIORITY_HIGH:
55 prio = ABOVE_NORMAL_PRIORITY_CLASS;
60 case GNUNET_SCHEDULER_PRIORITY_BACKGROUND:
62 prio = BELOW_NORMAL_PRIORITY_CLASS;
67 case GNUNET_SCHEDULER_PRIORITY_UI:
68 case GNUNET_SCHEDULER_PRIORITY_URGENT:
70 prio = HIGH_PRIORITY_CLASS;
75 case GNUNET_SCHEDULER_PRIORITY_IDLE:
77 prio = IDLE_PRIORITY_CLASS;
86 /* Set process priority */
88 SetPriorityClass (GetCurrentProcess (), prio);
90 if (proc == getpid ())
93 if ((-1 == nice (prio)) && (errno != 0))
95 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING |
96 GNUNET_ERROR_TYPE_BULK, "nice");
102 if (0 != setpriority (PRIO_PROCESS, proc, prio))
105 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING |
106 GNUNET_ERROR_TYPE_BULK, "setpriority");
107 return GNUNET_SYSERR;
119 * @param filename name of the binary
120 * @param ... NULL-terminated list of arguments to the process
121 * @return process ID of the new process, -1 on error
124 GNUNET_OS_start_process (const char *filename, ...)
135 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "fork");
139 va_start (ap, filename);
140 while (NULL != va_arg (ap, char *))
143 argv = GNUNET_malloc (sizeof (char *) * (argc + 1));
145 va_start (ap, filename);
146 while (NULL != (argv[argc] = va_arg (ap, char *)))
149 execvp (filename, argv);
150 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "execvp", filename);
160 * @param filename name of the binary
161 * @param argv NULL-terminated list of arguments to the process
162 * @return process ID of the new process, -1 on error
165 GNUNET_OS_start_process_v (const char *filename, char *const argv[])
173 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "fork");
176 execvp (filename, argv);
177 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "execvp", filename);
186 /* end of os_priority.c */