CUBRID Engine  latest
broker_process_info.c
Go to the documentation of this file.
1 /*
2  * Copyright 2008 Search Solution Corporation
3  * Copyright 2016 CUBRID Corporation
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */
18 
19 
20 /*
21  * broker_process_info.c -
22  */
23 
24 #ident "$Id$"
25 
26 #include <stdio.h>
27 #include <stdlib.h>
28 #include <errno.h>
29 #include <string.h>
30 
31 #if !defined(WINDOWS)
32 #include <unistd.h>
33 #endif
34 
35 #if defined(SOLARIS)
36 #include <fcntl.h>
37 #include <sys/procfs.h>
38 #elif defined(HPUX)
39 #include <sys/pstat.h>
40 #elif defined(AIX)
41 #include <procinfo.h>
42 #elif defined(UNIXWARE7)
43 #include <sys/procfs.h>
44 #include <fcntl.h>
45 #elif defined(LINUX) || defined(ALPHA_LINUX)
46 #include <fcntl.h>
47 #include <string.h>
48 #include <sys/procfs.h>
49 #endif
50 
51 #include "cas_common.h"
52 #include "broker_process_info.h"
53 
54 #if defined(HPUX)
55 #include "hp_pstat.h"
56 #endif
57 
58 #if defined(SOLARIS)
59 int
60 get_psinfo (int pid, T_PSINFO * ps)
61 {
62  int procfd;
63  struct prstatus pstatus;
64  struct prpsinfo pinfo;
65  const char *procdir = "/proc";
66  char pname[128];
67 
68  memset (ps, 0, sizeof (T_PSINFO));
69 
70  sprintf (pname, "%s/%05d", procdir, pid);
71 
72  if ((procfd = open (pname, O_RDONLY)) == -1)
73  {
74  return -1;
75  }
76 
77  if (ioctl (procfd, PIOCSTATUS, (char *) &pstatus) == -1)
78  {
79  close (procfd);
80  return -1;
81  }
82  if (ioctl (procfd, PIOCPSINFO, (char *) &pinfo) == -1)
83  {
84  close (procfd);
85  return -1;
86  }
87 
88  close (procfd);
89 
90  ps->num_thr = pstatus.pr_nlwp;
91  ps->pcpu = (double) pinfo.pr_pctcpu / 0x8000 * 100;
92  ps->cpu_time = pinfo.pr_time.tv_sec;
93 
94  return 0;
95 }
96 #elif defined(HPUX10_2)
97 int
98 get_psinfo (int pid, T_PSINFO * ps)
99 {
100  return -1;
101 }
102 #elif defined(HPUX)
103 int
104 get_psinfo (int pid, T_PSINFO * ps)
105 {
106  struct pst_status info;
107 
108  memset (ps, 0, sizeof (T_PSINFO));
109 
110  if (HP_PSTAT_GETPROC (&info, pid) < 0)
111  {
112  return -1;
113  }
114 
115  ps->num_thr = info.pst_nlwps;
116  ps->pcpu = info.pst_pctcpu * 100;
117  ps->cpu_time = info.pst_utime + info.pst_stime;
118 
119  return (0);
120 }
121 #else
122 int
123 get_psinfo (int pid, T_PSINFO * ps)
124 {
125  return -1;
126 }
127 #endif
pid_t pid
Definition: dynamic_load.c:955
int get_psinfo(int pid, T_PSINFO *ps)