2 /* Copyright Gerhard Rieger */
3 /* Published under the GNU General Public License V.2, see file COPYING */
5 /* the subroutine procan makes a "PROCess ANalysis". It gathers information
6 about the process environment it is running in without modifying its state
10 #include "xiosysincludes.h"
18 #include <sys/resource.h>
22 /* dirty workaround so we dont get an error on AIX when getting linked with
24 int allow_severity
, deny_severity
;
27 int procan(FILE *outfile
) {
29 /*filan(0, outfile);*/
31 /* controlling terminal */
32 fprintf(outfile
, "process id = "F_pid
"\n", Getpid());
33 fprintf(outfile
, "process parent id = "F_pid
"\n", Getppid());
36 if ((fd
= Open("/dev/tty", O_NOCTTY
, 0)) < 0) {
37 fprintf(outfile
, "controlling terminal: -\n");
40 fprintf(outfile
, "controlling terminal: \"%s\"\n", Ttyname(fd
));
42 char procpath
[PATH_MAX
], devpath
[PATH_MAX
+1];
44 sprintf(procpath
, "/proc/"F_pid
"/fd/%d", Getpid(), 0 /*! fd*/);
45 if ((devlen
= Readlink(procpath
, devpath
, sizeof(devpath
))) < 0) {
48 devpath
[devlen
] = '\0';
49 fprintf(outfile
, "controlling terminal: \"%s\"\n", devpath
);
54 fprintf(outfile
, "process group id = "F_pid
"\n", Getpgrp());
56 fprintf(outfile
, "process session id = "F_pid
"\n", Getsid(0));
58 fprintf(outfile
, "process group id if fg process / stdin = "F_pid
"\n", Tcgetpgrp(0));
59 fprintf(outfile
, "process group id if fg process / stdout = "F_pid
"\n", Tcgetpgrp(1));
60 fprintf(outfile
, "process group id if fg process / stderr = "F_pid
"\n", Tcgetpgrp(2));
63 if ((fd
= Open("/dev/tty", O_RDWR
, 0600)) >= 0) {
64 fprintf(outfile
, "process has a controlling terminal\n");
67 fprintf(outfile
, "process does not have a controlling terminal\n");
71 /* process owner, groups */
72 fprintf(outfile
, "user id = "F_uid
"\n", Getuid());
73 fprintf(outfile
, "effective user id = "F_uid
"\n", Geteuid());
74 fprintf(outfile
, "group id = "F_gid
"\n", Getgid());
75 fprintf(outfile
, "effective group id = "F_gid
"\n", Getegid());
80 fprintf(outfile
, "\nRESOURCE LIMITS\n");
81 fprintf(outfile
, "resource current maximum\n");
82 if (getrlimit(RLIMIT_CPU
, &rlim
) < 0) {
83 Warn2("getrlimit(RLIMIT_CPU, %p): %s", &rlim
, strerror(errno
));
86 "cpu time (seconds) %24"F_rlim_max
"%24"F_rlim_max
"\n",
87 rlim
.rlim_cur
, rlim
.rlim_max
);
89 if (getrlimit(RLIMIT_FSIZE
, &rlim
) < 0) {
90 Warn2("getrlimit(RLIMIT_FSIZE, %p): %s", &rlim
, strerror(errno
));
93 "file size (blocks) %24"F_rlim_max
"%24"F_rlim_max
"\n",
94 rlim
.rlim_cur
, rlim
.rlim_max
);
96 if (getrlimit(RLIMIT_DATA
, &rlim
) < 0) {
97 Warn2("getrlimit(RLIMIT_DATA, %p): %s", &rlim
, strerror(errno
));
100 "data seg size (kbytes) %24"F_rlim_max
"%24"F_rlim_max
"\n",
101 rlim
.rlim_cur
, rlim
.rlim_max
);
103 if (getrlimit(RLIMIT_STACK
, &rlim
) < 0) {
104 Warn2("getrlimit(RLIMIT_STACK, %p): %s", &rlim
, strerror(errno
));
107 "stack size (blocks) %24"F_rlim_max
"%24"F_rlim_max
"\n",
108 rlim
.rlim_cur
, rlim
.rlim_max
);
110 if (getrlimit(RLIMIT_CORE
, &rlim
) < 0) {
111 Warn2("getrlimit(RLIMIT_CORE, %p): %s", &rlim
, strerror(errno
));
114 "core file size (blocks) %24"F_rlim_max
"%24"F_rlim_max
"\n",
115 rlim
.rlim_cur
, rlim
.rlim_max
);
117 #ifdef RLIMIT_RSS /* Linux, AIX; not Cygwin */
118 if (getrlimit(RLIMIT_RSS
, &rlim
) < 0) {
119 Warn2("getrlimit(RLIMIT_RSS, %p): %s", &rlim
, strerror(errno
));
122 "max resident set size %24"F_rlim_max
"%24"F_rlim_max
"\n",
123 rlim
.rlim_cur
, rlim
.rlim_max
);
126 #ifdef RLIMIT_NPROC /* Linux, not AIX, Cygwin */
127 if (getrlimit(RLIMIT_NPROC
, &rlim
) < 0) {
128 Warn2("getrlimit(RLIMIT_NPROC, %p): %s", &rlim
, strerror(errno
));
131 "max user processes %24"F_rlim_max
"%24"F_rlim_max
"\n",
132 rlim
.rlim_cur
, rlim
.rlim_max
);
135 #ifdef RLIMIT_NOFILE /* not AIX 4.1 */
136 if (getrlimit(RLIMIT_NOFILE
, &rlim
) < 0) {
137 Warn2("getrlimit(RLIMIT_NOFILE, %p): %s", &rlim
, strerror(errno
));
140 "open files %24"F_rlim_max
"%24"F_rlim_max
"\n",
141 rlim
.rlim_cur
, rlim
.rlim_max
);
144 #ifdef RLIMIT_MEMLOCK /* Linux, not AIX, Cygwin */
145 if (getrlimit(RLIMIT_MEMLOCK
, &rlim
) < 0) {
146 Warn2("getrlimit(RLIMIT_MEMLOCK, %p): %s", &rlim
, strerror(errno
));
149 "max locked-in-memory\n address space %24"F_rlim_max
"%24"F_rlim_max
"\n",
150 rlim
.rlim_cur
, rlim
.rlim_max
);
154 if (getrlimit(RLIMIT_AS
, &rlim
) < 0) {
155 Warn2("getrlimit(RLIMIT_AS, %p): %s", &rlim
, strerror(errno
));
158 "virtual memory (kbytes) %24"F_rlim_max
"%24"F_rlim_max
"\n",
159 rlim
.rlim_cur
, rlim
.rlim_max
);
164 /* file descriptors */
166 /* what was this for?? */