File: bsdi.h

package info (click to toggle)
libproc-processtable-perl 0.637-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 672 kB
  • sloc: ansic: 5,765; perl: 568; makefile: 15
file content (148 lines) | stat: -rw-r--r-- 3,345 bytes parent folder | download | duplicates (13)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#include <sys/types.h>
#include <sys/param.h>
#include <sys/mount.h>
#include <sys/stat.h>
#include <sys/proc.h>
#include <sys/sysctl.h>
#include <fcntl.h>
#include <kvm.h>
#include <limits.h>
#include <unistd.h>
#include <sys/user.h>
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <math.h>

/* Grab the maximum argument length */
#include <sys/syslimits.h>

#define MAXARGLN	ARG_MAX

/**********************************************************/
/* Copyright (c) 1999, Magic Software Development, Inc.   */ 
/* Author:  Sean Ray Eskins. <sean@gilasoft.com>          */
/* This file is free software; it can be modified and/or  */
/* redistributed under the same terms as Perl itself.     */
/**********************************************************/

/**********************************/
/* Process state names we return  */
/**********************************/
#define SLEEP   "SLEEP"
#define RUN     "RUN"
#define IDLE    "IDLE"
#define STOP    "STOP"
#define ZOMBIE  "ZOMBIE"
#define UNKNOWN "UNKNOWN"

/* We are using kinfo_proc structure and kvm_getprocs to access */
/* processes from the kernel, so we don't need the procstat structure */
/* present in perl modules for other operating systems (ie: we */
/* are not accessing the processes from a proc directory) */
/* All processes are accessed straight from the kernel, so we don't */
/* need to mess around with the format much. */

/*******************************************************/
/* Some scripts needed to round off to top two digits  */
/* of "miliseconds", so that only the first two digits */
/* are printed to the m:ss.[miliseconds] time field of */
/* Fields[] below.                                     */
/*******************************************************/


/* power(int base, int pow) -- takes integer base to power pow. . . */ 
/*                             for use with roundit(int integer). */

int power(int base, int pow) {
  int count, result;
  count=1;
  result=1;
  while (count <= pow) {
    result=base*result;
    count++;
  }
  return(result);
} 


/* roundit(int) -- rounds a 4-, 5-, or 6-digit number to its highest */
/*                 two places. */


int roundit(int integer) {
  char string[10];
  int length;
  int newnum;
  int cutoff;
  int pow10;
  sprintf(string, "%d", integer);
  length=strlen(string);
  cutoff=length - 2;
  pow10=power(10, cutoff);
  newnum=integer/pow10;
  return(newnum); 
}
  


/* We need to pass in a cap for ignore, lower for store on object */
/* We can just lc these! */
static char Defaultformat[] = "iiiiiisissssssls";

/* Mapping of field to type */
static char* Fields[] = {
  "uid",                   /* ruid from kernel */
#define F_UID 0 

  "gid",                   /* rgid from kernel */
#define F_GID 1

  "pid",
#define F_PID 2

  "ppid",
#define F_PPID 3

  "pgrp",
#define F_PGRP 4

  "priority", 
#define F_PRIORITY 5

  "sess",
#define F_SESSION 6

  "leader",
#define F_LEADER 7

  "time",
#define F_TIME 8              

  "wchan",
#define F_WCHAN 9

  "fname",                /* command name (without args) */
#define F_NAME  10

  "state",
#define F_STATE 11

  "started",
#define F_STARTED 12

  "ttydev",
#define F_TTYDEV 13

  "ttynum",
#define F_TTYNUM 14
  "cmndline"
#define F_CMNDLINE 15

#define F_LASTFIELD 15
};