1 | /* $Id: proctime.c,v 1.1.1.1 2003-01-02 04:56:12 ghudson Exp $ */ |
---|
2 | |
---|
3 | /* Copyright (C) 1998-99 Martin Baulig |
---|
4 | This file is part of LibGTop 1.0. |
---|
5 | |
---|
6 | Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998. |
---|
7 | |
---|
8 | LibGTop is free software; you can redistribute it and/or modify it |
---|
9 | under the terms of the GNU General Public License as published by |
---|
10 | the Free Software Foundation; either version 2 of the License, |
---|
11 | or (at your option) any later version. |
---|
12 | |
---|
13 | LibGTop is distributed in the hope that it will be useful, but WITHOUT |
---|
14 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
---|
15 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
---|
16 | for more details. |
---|
17 | |
---|
18 | You should have received a copy of the GNU General Public License |
---|
19 | along with LibGTop; see the file COPYING. If not, write to the |
---|
20 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
---|
21 | Boston, MA 02111-1307, USA. |
---|
22 | */ |
---|
23 | |
---|
24 | #include <glibtop.h> |
---|
25 | #include <glibtop/proctime.h> |
---|
26 | |
---|
27 | #include <glibtop_suid.h> |
---|
28 | |
---|
29 | #include <sys/user.h> |
---|
30 | #include <sys/time.h> |
---|
31 | |
---|
32 | static const unsigned long _glibtop_sysdeps_proc_time = |
---|
33 | (1L << GLIBTOP_PROC_TIME_UTIME) + (1L << GLIBTOP_PROC_TIME_CUTIME) + |
---|
34 | (1L << GLIBTOP_PROC_TIME_STIME) + (1L << GLIBTOP_PROC_TIME_CSTIME) + |
---|
35 | (1L << GLIBTOP_PROC_TIME_START_TIME); |
---|
36 | |
---|
37 | /* Init function. */ |
---|
38 | |
---|
39 | void |
---|
40 | glibtop_init_proc_time_p (glibtop *server) |
---|
41 | { |
---|
42 | server->sysdeps.proc_time = _glibtop_sysdeps_proc_time; |
---|
43 | } |
---|
44 | |
---|
45 | /* Provides detailed information about a process. */ |
---|
46 | |
---|
47 | void |
---|
48 | glibtop_get_proc_time_p (glibtop *server, glibtop_proc_time *buf, |
---|
49 | pid_t pid) |
---|
50 | { |
---|
51 | struct user u; |
---|
52 | int ret; |
---|
53 | |
---|
54 | glibtop_init_p (server, GLIBTOP_SYSDEPS_PROC_TIME, 0); |
---|
55 | |
---|
56 | memset (buf, 0, sizeof (glibtop_proc_time)); |
---|
57 | |
---|
58 | /* !!! THE FOLLOWING CODE RUNS SUID ROOT - CHANGE WITH CAUTION !!! */ |
---|
59 | |
---|
60 | glibtop_suid_enter (server); |
---|
61 | |
---|
62 | ret = table (TBL_UAREA, pid, (char *) &u, 1, |
---|
63 | sizeof (struct user)); |
---|
64 | |
---|
65 | glibtop_suid_leave (server); |
---|
66 | |
---|
67 | /* !!! END OF SUID ROOT PART !!! */ |
---|
68 | |
---|
69 | if (ret != 1) return; |
---|
70 | |
---|
71 | buf->start_time = u.u_start.tv_sec; |
---|
72 | |
---|
73 | buf->utime = u.u_ru.ru_utime.tv_sec; |
---|
74 | buf->stime = u.u_ru.ru_stime.tv_sec; |
---|
75 | buf->cutime = u.u_cru.ru_utime.tv_sec; |
---|
76 | buf->cstime = u.u_cru.ru_stime.tv_sec; |
---|
77 | |
---|
78 | buf->flags = _glibtop_sysdeps_proc_time; |
---|
79 | } |
---|