1 /* Copyright (C) 1994,95,96,97,2000,02 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, write to the Free
16 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
21 #include <hurd/resource.h>
23 /* Return the highest priority of any process specified by WHICH and WHO
24 (see <sys/resource.h>); if WHO is zero, the current process, process group,
25 or user (as specified by WHO) is used. A lower priority number means higher
26 priority. Priorities range from PRIO_MIN to PRIO_MAX. */
28 getpriority (enum __priority_which which, id_t who)
32 struct procinfo *pip; /* Just for sizeof. */
33 int pibuf[sizeof *pip + 2 * sizeof (pip->threadinfos[0])], *pi = pibuf;
34 unsigned int pisize = sizeof pibuf / sizeof pibuf[0];
36 error_t getonepriority (pid_t pid, struct procinfo *pip)
43 unsigned int oldpisize = pisize;
46 int flags = PI_FETCH_TASKINFO;
47 onerr = __USEPORT (PROC, __proc_getprocinfo (port, pid, &flags,
51 __vm_deallocate (__mach_task_self (), (vm_address_t) tw, twsz);
52 if (pi != oldpi && oldpi != pibuf)
53 /* Old buffer from last call was not reused; free it. */
54 __vm_deallocate (__mach_task_self (),
55 (vm_address_t) oldpi, oldpisize * sizeof pi[0]);
56 pip = (struct procinfo *) pi;
58 #ifdef TASK_SCHED_TIMESHARE_INFO
59 if (!onerr && pip->timeshare_base_info.base_priority > maxpri)
60 maxpri = pip->timeshare_base_info.base_priority;
62 if (!onerr && pip->taskinfo.base_priority > maxpri)
63 maxpri = pip->taskinfo.base_priority;
69 err = _hurd_priority_which_map (which, who,
70 getonepriority, PI_FETCH_TASKINFO);
73 __vm_deallocate (__mach_task_self (),
74 (vm_address_t) pi, pisize * sizeof pi[0]);
76 if (!err && maxpri == INT_MIN)
77 /* No error, but no pids found. */
81 return __hurd_fail (err);
83 return MACH_PRIORITY_TO_NICE (maxpri);