Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
adam.huang
htop
Commits
40f3391a
Commit
40f3391a
authored
Mar 16, 2015
by
Hisham Muhammad
Browse files
Merge branch 'wip' of
https://github.com/hishamhm/htop
into freebsd
parents
a44a64d0
be1700cf
Changes
10
Expand all
Show whitespace changes
Inline
Side-by-side
AvailableColumnsPanel.c
View file @
40f3391a
...
@@ -75,7 +75,7 @@ AvailableColumnsPanel* AvailableColumnsPanel_new(Panel* columns) {
...
@@ -75,7 +75,7 @@ AvailableColumnsPanel* AvailableColumnsPanel_new(Panel* columns) {
Panel_setHeader
(
super
,
"Available Columns"
);
Panel_setHeader
(
super
,
"Available Columns"
);
for
(
int
i
=
1
;
i
<
LAST_PROCESSFIELD
;
i
++
)
{
for
(
int
i
=
1
;
i
<
Platform_numberOfFields
;
i
++
)
{
if
(
i
!=
COMM
&&
Process_fields
[
i
].
description
)
{
if
(
i
!=
COMM
&&
Process_fields
[
i
].
description
)
{
char
description
[
256
];
char
description
[
256
];
snprintf
(
description
,
sizeof
(
description
),
"%s - %s"
,
Process_fields
[
i
].
name
,
Process_fields
[
i
].
description
);
snprintf
(
description
,
sizeof
(
description
),
"%s - %s"
,
Process_fields
[
i
].
name
,
Process_fields
[
i
].
description
);
...
...
ColumnsPanel.c
View file @
40f3391a
...
@@ -135,7 +135,7 @@ ColumnsPanel* ColumnsPanel_new(Settings* settings) {
...
@@ -135,7 +135,7 @@ ColumnsPanel* ColumnsPanel_new(Settings* settings) {
}
}
int
ColumnsPanel_fieldNameToIndex
(
const
char
*
name
)
{
int
ColumnsPanel_fieldNameToIndex
(
const
char
*
name
)
{
for
(
int
j
=
1
;
j
<=
LAST_PROCESSFIELD
;
j
++
)
{
for
(
int
j
=
1
;
j
<=
Platform_numberOfFields
;
j
++
)
{
if
(
String_eq
(
name
,
Process_fields
[
j
].
name
))
{
if
(
String_eq
(
name
,
Process_fields
[
j
].
name
))
{
return
j
;
return
j
;
}
}
...
...
Process.c
View file @
40f3391a
...
@@ -41,26 +41,40 @@ in the source distribution for its full text.
...
@@ -41,26 +41,40 @@ in the source distribution for its full text.
#define PROCESS_FLAG_IO 0x0001
#define PROCESS_FLAG_IO 0x0001
#ifndef Process_isKernelThread
typedef enum ProcessFields {
#define Process_isKernelThread(_process) (_process->pgrp == 0)
PID = 1,
#endif
COMM = 2,
STATE = 3,
#ifndef Process_isUserlandThread
PPID = 4,
#define Process_isUserlandThread(_process) (_process->pid != _process->tgid)
PGRP = 5,
#endif
SESSION = 6,
TTY_NR = 7,
#ifndef Process_isThread
TPGID = 8,
#define Process_isThread(_process) (Process_isUserlandThread(_process) || Process_isKernelThread(_process))
MINFLT = 10,
#endif
MAJFLT = 12,
PRIORITY = 18,
typedef int ProcessField;
NICE = 19,
STARTTIME = 21,
M_SIZE = 39,
M_RESIDENT = 40,
ST_UID = 46,
PERCENT_CPU = 47,
PERCENT_MEM = 48,
USER = 49,
TIME = 50,
NLWP = 51,
TGID = 52,
} ProcessField;
typedef struct Process_ {
typedef struct Process_ {
Object super;
Object super;
struct Settings_* settings;
struct Settings_* settings;
unsigned long long int time;
pid_t pid;
pid_t pid;
pid_t ppid;
pid_t tgid;
char* comm;
char* comm;
int indent;
int indent;
...
@@ -71,73 +85,30 @@ typedef struct Process_ {
...
@@ -71,73 +85,30 @@ typedef struct Process_ {
bool tag;
bool tag;
bool showChildren;
bool showChildren;
bool show;
bool show;
pid_t ppid;
unsigned int pgrp;
unsigned int pgrp;
unsigned int session;
unsigned int session;
unsigned int tty_nr;
unsigned int tty_nr;
pid_t tgid;
int tpgid;
int tpgid;
uid_t st_uid;
unsigned long int flags;
unsigned long int flags;
uid_t st_uid;
float percent_cpu;
float percent_cpu;
float percent_mem;
float percent_mem;
char* user;
char* user;
unsigned long long int utime;
unsigned long long int stime;
unsigned long long int cutime;
unsigned long long int cstime;
long int priority;
long int priority;
long int nice;
long int nice;
long int nlwp;
long int nlwp;
char starttime_show[8];
char starttime_show[8];
time_t starttime_ctime;
time_t starttime_ctime;
#ifdef HAVE_TASKSTATS
unsigned long long io_rchar;
unsigned long long io_wchar;
unsigned long long io_syscr;
unsigned long long io_syscw;
unsigned long long io_read_bytes;
unsigned long long io_write_bytes;
unsigned long long io_cancelled_write_bytes;
unsigned long long io_rate_read_time;
unsigned long long io_rate_write_time;
double io_rate_read_bps;
double io_rate_write_bps;
#endif
int processor;
long m_size;
long m_size;
long m_resident;
long m_resident;
long m_share;
long m_trs;
long m_drs;
long m_lrs;
long m_dt;
#ifdef HAVE_OPENVZ
unsigned int ctid;
unsigned int vpid;
#endif
#ifdef HAVE_VSERVER
unsigned int vxid;
#endif
#ifdef HAVE_CGROUP
char* cgroup;
#endif
#ifdef HAVE_OOM
unsigned int oom;
#endif
int exit_signal;
int exit_signal;
unsigned long int minflt;
unsigned long int minflt;
unsigned long int cminflt;
unsigned long int majflt;
unsigned long int majflt;
unsigned long int cmajflt;
#ifdef DEBUG
#ifdef DEBUG
long int itrealvalue;
long int itrealvalue;
unsigned long int vsize;
unsigned long int vsize;
...
@@ -166,8 +137,15 @@ typedef struct ProcessFieldData_ {
...
@@ -166,8 +137,15 @@ typedef struct ProcessFieldData_ {
int flags;
int flags;
} ProcessFieldData;
} ProcessFieldData;
// Implemented in platform-specific code:
void Process_setupColumnWidths();
void Process_writeField(Process* this, RichString* str, ProcessField field);
void Process_writeField(Process* this, RichString* str, ProcessField field);
long Process_compare(const void* v1, const void* v2);
long Process_compare(const void* v1, const void* v2);
void Process_delete(Object* cast);
bool Process_isThread(Process* this);
extern ProcessFieldData Process_fields[];
extern char* Process_pidFormat;
extern char* Process_tpgidFormat;
}*/
}*/
...
@@ -181,7 +159,7 @@ static int Process_getuid = -1;
...
@@ -181,7 +159,7 @@ static int Process_getuid = -1;
#define ONE_DECIMAL_M (ONE_DECIMAL_K * ONE_DECIMAL_K)
#define ONE_DECIMAL_M (ONE_DECIMAL_K * ONE_DECIMAL_K)
#define ONE_DECIMAL_G (ONE_DECIMAL_M * ONE_DECIMAL_K)
#define ONE_DECIMAL_G (ONE_DECIMAL_M * ONE_DECIMAL_K)
static
void
Process_humanNumber
(
RichString
*
str
,
unsigned
long
number
,
bool
coloring
)
{
void
Process_humanNumber
(
RichString
*
str
,
unsigned
long
number
,
bool
coloring
)
{
char
buffer
[
11
];
char
buffer
[
11
];
int
len
;
int
len
;
...
@@ -229,7 +207,7 @@ static void Process_humanNumber(RichString* str, unsigned long number, bool colo
...
@@ -229,7 +207,7 @@ static void Process_humanNumber(RichString* str, unsigned long number, bool colo
RichString_appendn
(
str
,
processColor
,
buffer
,
len
);
RichString_appendn
(
str
,
processColor
,
buffer
,
len
);
}
}
static
void
Process_colorNumber
(
RichString
*
str
,
unsigned
long
long
number
,
bool
coloring
)
{
void
Process_colorNumber
(
RichString
*
str
,
unsigned
long
long
number
,
bool
coloring
)
{
char
buffer
[
14
];
char
buffer
[
14
];
int
largeNumberColor
=
CRT_colors
[
LARGE_NUMBER
];
int
largeNumberColor
=
CRT_colors
[
LARGE_NUMBER
];
...
@@ -258,7 +236,7 @@ static void Process_colorNumber(RichString* str, unsigned long long number, bool
...
@@ -258,7 +236,7 @@ static void Process_colorNumber(RichString* str, unsigned long long number, bool
static
double
jiffy
=
0
.
0
;
static
double
jiffy
=
0
.
0
;
static
void
Process_printTime
(
RichString
*
str
,
unsigned
long
long
t
)
{
void
Process_printTime
(
RichString
*
str
,
unsigned
long
long
t
)
{
if
(
jiffy
==
0
.
0
)
jiffy
=
sysconf
(
_SC_CLK_TCK
);
if
(
jiffy
==
0
.
0
)
jiffy
=
sysconf
(
_SC_CLK_TCK
);
double
jiffytime
=
1
.
0
/
jiffy
;
double
jiffytime
=
1
.
0
/
jiffy
;
...
@@ -307,7 +285,7 @@ static inline void Process_writeCommand(Process* this, int attr, int baseattr, R
...
@@ -307,7 +285,7 @@ static inline void Process_writeCommand(Process* this, int attr, int baseattr, R
}
}
}
}
static
inline
void
Process_outputRate
(
RichString
*
str
,
char
*
buffer
,
int
n
,
double
rate
,
int
coloring
)
{
void
Process_outputRate
(
RichString
*
str
,
char
*
buffer
,
int
n
,
double
rate
,
int
coloring
)
{
int
largeNumberColor
=
CRT_colors
[
LARGE_NUMBER
];
int
largeNumberColor
=
CRT_colors
[
LARGE_NUMBER
];
int
processMegabytesColor
=
CRT_colors
[
PROCESS_MEGABYTES
];
int
processMegabytesColor
=
CRT_colors
[
PROCESS_MEGABYTES
];
int
processColor
=
CRT_colors
[
PROCESS
];
int
processColor
=
CRT_colors
[
PROCESS
];
...
@@ -338,19 +316,24 @@ void Process_writeDefaultField(Process* this, RichString* str, ProcessField fiel
...
@@ -338,19 +316,24 @@ void Process_writeDefaultField(Process* this, RichString* str, ProcessField fiel
bool
coloring
=
this
->
settings
->
highlightMegabytes
;
bool
coloring
=
this
->
settings
->
highlightMegabytes
;
switch
(
field
)
{
switch
(
field
)
{
case
PID
:
snprintf
(
buffer
,
n
,
Process_pidFormat
,
this
->
pid
);
break
;
case
PERCENT_CPU
:
{
case
PPID
:
snprintf
(
buffer
,
n
,
Process_pidFormat
,
this
->
ppid
);
break
;
if
(
this
->
percent_cpu
>
999
.
9
)
{
case
PGRP
:
snprintf
(
buffer
,
n
,
Process_pidFormat
,
this
->
pgrp
);
break
;
snprintf
(
buffer
,
n
,
"%4d "
,
(
unsigned
int
)
this
->
percent_cpu
);
case
SESSION
:
snprintf
(
buffer
,
n
,
Process_pidFormat
,
this
->
session
);
break
;
}
else
if
(
this
->
percent_cpu
>
99
.
9
)
{
case
TTY_NR
:
snprintf
(
buffer
,
n
,
"%5u "
,
this
->
tty_nr
);
break
;
snprintf
(
buffer
,
n
,
"%3d. "
,
(
unsigned
int
)
this
->
percent_cpu
);
case
TGID
:
snprintf
(
buffer
,
n
,
Process_pidFormat
,
this
->
tgid
);
break
;
}
else
{
case
TPGID
:
snprintf
(
buffer
,
n
,
Process_tpgidFormat
,
this
->
tpgid
);
break
;
snprintf
(
buffer
,
n
,
"%4.1f "
,
this
->
percent_cpu
);
case
MINFLT
:
Process_colorNumber
(
str
,
this
->
minflt
,
coloring
);
return
;
}
case
CMINFLT
:
Process_colorNumber
(
str
,
this
->
cminflt
,
coloring
);
return
;
break
;
case
MAJFLT
:
Process_colorNumber
(
str
,
this
->
majflt
,
coloring
);
return
;
}
case
CMAJFLT
:
Process_colorNumber
(
str
,
this
->
cmajflt
,
coloring
);
return
;
case
PERCENT_MEM
:
{
case
PROCESSOR
:
snprintf
(
buffer
,
n
,
"%3d "
,
Settings_cpuId
(
this
->
settings
,
this
->
processor
));
break
;
if
(
this
->
percent_mem
>
99
.
9
)
{
case
NLWP
:
snprintf
(
buffer
,
n
,
"%4ld "
,
this
->
nlwp
);
break
;
snprintf
(
buffer
,
n
,
"100. "
);
}
else
{
snprintf
(
buffer
,
n
,
"%4.1f "
,
this
->
percent_mem
);
}
break
;
}
case
COMM
:
{
case
COMM
:
{
if
(
this
->
settings
->
highlightThreads
&&
Process_isThread
(
this
))
{
if
(
this
->
settings
->
highlightThreads
&&
Process_isThread
(
this
))
{
attr
=
CRT_colors
[
PROCESS_THREAD
];
attr
=
CRT_colors
[
PROCESS_THREAD
];
...
@@ -384,6 +367,30 @@ void Process_writeDefaultField(Process* this, RichString* str, ProcessField fiel
...
@@ -384,6 +367,30 @@ void Process_writeDefaultField(Process* this, RichString* str, ProcessField fiel
return
;
return
;
}
}
}
}
case
MAJFLT
:
Process_colorNumber
(
str
,
this
->
majflt
,
coloring
);
return
;
case
MINFLT
:
Process_colorNumber
(
str
,
this
->
minflt
,
coloring
);
return
;
case
M_RESIDENT
:
Process_humanNumber
(
str
,
this
->
m_resident
*
PAGE_SIZE_KB
,
coloring
);
return
;
case
M_SIZE
:
Process_humanNumber
(
str
,
this
->
m_size
*
PAGE_SIZE_KB
,
coloring
);
return
;
case
NICE
:
{
snprintf
(
buffer
,
n
,
"%3ld "
,
this
->
nice
);
attr
=
this
->
nice
<
0
?
CRT_colors
[
PROCESS_HIGH_PRIORITY
]
:
this
->
nice
>
0
?
CRT_colors
[
PROCESS_LOW_PRIORITY
]
:
attr
;
break
;
}
case
NLWP
:
snprintf
(
buffer
,
n
,
"%4ld "
,
this
->
nlwp
);
break
;
case
PGRP
:
snprintf
(
buffer
,
n
,
Process_pidFormat
,
this
->
pgrp
);
break
;
case
PID
:
snprintf
(
buffer
,
n
,
Process_pidFormat
,
this
->
pid
);
break
;
case
PPID
:
snprintf
(
buffer
,
n
,
Process_pidFormat
,
this
->
ppid
);
break
;
case
PRIORITY
:
{
if
(
this
->
priority
==
-
100
)
snprintf
(
buffer
,
n
,
" RT "
);
else
snprintf
(
buffer
,
n
,
"%3ld "
,
this
->
priority
);
break
;
}
case
SESSION
:
snprintf
(
buffer
,
n
,
Process_pidFormat
,
this
->
session
);
break
;
case
STARTTIME
:
snprintf
(
buffer
,
n
,
"%s"
,
this
->
starttime_show
);
break
;
case
STATE
:
{
case
STATE
:
{
snprintf
(
buffer
,
n
,
"%c "
,
this
->
state
);
snprintf
(
buffer
,
n
,
"%c "
,
this
->
state
);
switch
(
this
->
state
)
{
switch
(
this
->
state
)
{
...
@@ -396,28 +403,11 @@ void Process_writeDefaultField(Process* this, RichString* str, ProcessField fiel
...
@@ -396,28 +403,11 @@ void Process_writeDefaultField(Process* this, RichString* str, ProcessField fiel
}
}
break
;
break
;
}
}
case
PRIORITY
:
{
if
(
this
->
priority
==
-
100
)
snprintf
(
buffer
,
n
,
" RT "
);
else
snprintf
(
buffer
,
n
,
"%3ld "
,
this
->
priority
);
break
;
}
case
NICE
:
{
snprintf
(
buffer
,
n
,
"%3ld "
,
this
->
nice
);
attr
=
this
->
nice
<
0
?
CRT_colors
[
PROCESS_HIGH_PRIORITY
]
:
this
->
nice
>
0
?
CRT_colors
[
PROCESS_LOW_PRIORITY
]
:
attr
;
break
;
}
case
M_DRS
:
Process_humanNumber
(
str
,
this
->
m_drs
*
PAGE_SIZE_KB
,
coloring
);
return
;
case
M_DT
:
Process_humanNumber
(
str
,
this
->
m_dt
*
PAGE_SIZE_KB
,
coloring
);
return
;
case
M_LRS
:
Process_humanNumber
(
str
,
this
->
m_lrs
*
PAGE_SIZE_KB
,
coloring
);
return
;
case
M_TRS
:
Process_humanNumber
(
str
,
this
->
m_trs
*
PAGE_SIZE_KB
,
coloring
);
return
;
case
M_SIZE
:
Process_humanNumber
(
str
,
this
->
m_size
*
PAGE_SIZE_KB
,
coloring
);
return
;
case
M_RESIDENT
:
Process_humanNumber
(
str
,
this
->
m_resident
*
PAGE_SIZE_KB
,
coloring
);
return
;
case
M_SHARE
:
Process_humanNumber
(
str
,
this
->
m_share
*
PAGE_SIZE_KB
,
coloring
);
return
;
case
ST_UID
:
snprintf
(
buffer
,
n
,
"%4d "
,
this
->
st_uid
);
break
;
case
ST_UID
:
snprintf
(
buffer
,
n
,
"%4d "
,
this
->
st_uid
);
break
;
case
TIME
:
Process_printTime
(
str
,
this
->
time
);
return
;
case
TGID
:
snprintf
(
buffer
,
n
,
Process_pidFormat
,
this
->
tgid
);
break
;
case
TPGID
:
snprintf
(
buffer
,
n
,
Process_tpgidFormat
,
this
->
tpgid
);
break
;
case
TTY_NR
:
snprintf
(
buffer
,
n
,
"%5u "
,
this
->
tty_nr
);
break
;
case
USER
:
{
case
USER
:
{
if
(
Process_getuid
!=
(
int
)
this
->
st_uid
)
if
(
Process_getuid
!=
(
int
)
this
->
st_uid
)
attr
=
CRT_colors
[
PROCESS_SHADOW
];
attr
=
CRT_colors
[
PROCESS_SHADOW
];
...
@@ -432,55 +422,6 @@ void Process_writeDefaultField(Process* this, RichString* str, ProcessField fiel
...
@@ -432,55 +422,6 @@ void Process_writeDefaultField(Process* this, RichString* str, ProcessField fiel
}
}
break
;
break
;
}
}
case
UTIME
:
Process_printTime
(
str
,
this
->
utime
);
return
;
case
STIME
:
Process_printTime
(
str
,
this
->
stime
);
return
;
case
CUTIME
:
Process_printTime
(
str
,
this
->
cutime
);
return
;
case
CSTIME
:
Process_printTime
(
str
,
this
->
cstime
);
return
;
case
TIME
:
Process_printTime
(
str
,
this
->
utime
+
this
->
stime
);
return
;
case
PERCENT_CPU
:
{
if
(
this
->
percent_cpu
>
999
.
9
)
{
snprintf
(
buffer
,
n
,
"%4d "
,
(
unsigned
int
)
this
->
percent_cpu
);
}
else
if
(
this
->
percent_cpu
>
99
.
9
)
{
snprintf
(
buffer
,
n
,
"%3d. "
,
(
unsigned
int
)
this
->
percent_cpu
);
}
else
{
snprintf
(
buffer
,
n
,
"%4.1f "
,
this
->
percent_cpu
);
}
break
;
}
case
PERCENT_MEM
:
{
if
(
this
->
percent_mem
>
99
.
9
)
{
snprintf
(
buffer
,
n
,
"100. "
);
}
else
{
snprintf
(
buffer
,
n
,
"%4.1f "
,
this
->
percent_mem
);
}
break
;
}
case
STARTTIME
:
snprintf
(
buffer
,
n
,
"%s"
,
this
->
starttime_show
);
break
;
#ifdef HAVE_OPENVZ
case
CTID
:
snprintf
(
buffer
,
n
,
"%7u "
,
this
->
ctid
);
break
;
case
VPID
:
snprintf
(
buffer
,
n
,
Process_pidFormat
,
this
->
vpid
);
break
;
#endif
#ifdef HAVE_VSERVER
case
VXID
:
snprintf
(
buffer
,
n
,
"%5u "
,
this
->
vxid
);
break
;
#endif
#ifdef HAVE_TASKSTATS
case
RCHAR
:
Process_colorNumber
(
str
,
this
->
io_rchar
,
coloring
);
return
;
case
WCHAR
:
Process_colorNumber
(
str
,
this
->
io_wchar
,
coloring
);
return
;
case
SYSCR
:
Process_colorNumber
(
str
,
this
->
io_syscr
,
coloring
);
return
;
case
SYSCW
:
Process_colorNumber
(
str
,
this
->
io_syscw
,
coloring
);
return
;
case
RBYTES
:
Process_colorNumber
(
str
,
this
->
io_read_bytes
,
coloring
);
return
;
case
WBYTES
:
Process_colorNumber
(
str
,
this
->
io_write_bytes
,
coloring
);
return
;
case
CNCLWB
:
Process_colorNumber
(
str
,
this
->
io_cancelled_write_bytes
,
coloring
);
return
;
case
IO_READ_RATE
:
Process_outputRate
(
str
,
buffer
,
n
,
this
->
io_rate_read_bps
,
coloring
);
return
;
case
IO_WRITE_RATE
:
Process_outputRate
(
str
,
buffer
,
n
,
this
->
io_rate_write_bps
,
coloring
);
return
;
case
IO_RATE
:
Process_outputRate
(
str
,
buffer
,
n
,
this
->
io_rate_read_bps
+
this
->
io_rate_write_bps
,
coloring
);
return
;
#endif
#ifdef HAVE_CGROUP
case
CGROUP
:
snprintf
(
buffer
,
n
,
"%-10s "
,
this
->
cgroup
);
break
;
#endif
#ifdef HAVE_OOM
case
OOM
:
snprintf
(
buffer
,
n
,
Process_pidFormat
,
this
->
oom
);
break
;
#endif
default:
default:
snprintf
(
buffer
,
n
,
"- "
);
snprintf
(
buffer
,
n
,
"- "
);
}
}
...
@@ -503,9 +444,6 @@ static void Process_display(Object* cast, RichString* out) {
...
@@ -503,9 +444,6 @@ static void Process_display(Object* cast, RichString* out) {
void
Process_done
(
Process
*
this
)
{
void
Process_done
(
Process
*
this
)
{
assert
(
this
!=
NULL
);
assert
(
this
!=
NULL
);
free
(
this
->
comm
);
free
(
this
->
comm
);
#ifdef HAVE_CGROUP
free
(
this
->
cgroup
);
#endif
}
}
ObjectClass
Process_class
=
{
ObjectClass
Process_class
=
{
...
@@ -516,20 +454,12 @@ ObjectClass Process_class = {
...
@@ -516,20 +454,12 @@ ObjectClass Process_class = {
};
};
void
Process_init
(
Process
*
this
,
struct
Settings_
*
settings
)
{
void
Process_init
(
Process
*
this
,
struct
Settings_
*
settings
)
{
this
->
pid
=
0
;
this
->
settings
=
settings
;
this
->
settings
=
settings
;
this
->
tag
=
false
;
this
->
tag
=
false
;
this
->
showChildren
=
true
;
this
->
showChildren
=
true
;
this
->
show
=
true
;
this
->
show
=
true
;
this
->
updated
=
false
;
this
->
updated
=
false
;
this
->
utime
=
0
;
this
->
stime
=
0
;
this
->
comm
=
NULL
;
this
->
basenameOffset
=
-
1
;
this
->
basenameOffset
=
-
1
;
this
->
indent
=
0
;
#ifdef HAVE_CGROUP
this
->
cgroup
=
NULL
;
#endif
if
(
Process_getuid
==
-
1
)
Process_getuid
=
getuid
();
if
(
Process_getuid
==
-
1
)
Process_getuid
=
getuid
();
}
}
...
@@ -570,91 +500,56 @@ long Process_defaultCompare(const void* v1, const void* v2) {
...
@@ -570,91 +500,56 @@ long Process_defaultCompare(const void* v1, const void* v2) {
p2
=
(
Process
*
)
v1
;
p2
=
(
Process
*
)
v1
;
p1
=
(
Process
*
)
v2
;
p1
=
(
Process
*
)
v2
;
}
}
long
long
diff
;
switch
(
settings
->
sortKey
)
{
switch
(
settings
->
sortKey
)
{
case
PID
:
return
(
p1
->
pid
-
p2
->
pid
);
case
PPID
:
return
(
p1
->
ppid
-
p2
->
ppid
);
case
USER
:
return
strcmp
(
p1
->
user
?
p1
->
user
:
""
,
p2
->
user
?
p2
->
user
:
""
);
case
PRIORITY
:
return
(
p1
->
priority
-
p2
->
priority
);
case
PROCESSOR
:
return
(
p1
->
processor
-
p2
->
processor
);
case
SESSION
:
return
(
p1
->
session
-
p2
->
session
);
case
STATE
:
return
(
p1
->
state
-
p2
->
state
);
case
NICE
:
return
(
p1
->
nice
-
p2
->
nice
);
case
M_DRS
:
return
(
p2
->
m_drs
-
p1
->
m_drs
);
case
M_DT
:
return
(
p2
->
m_dt
-
p1
->
m_dt
);
case
M_LRS
:
return
(
p2
->
m_lrs
-
p1
->
m_lrs
);
case
M_TRS
:
return
(
p2
->
m_trs
-
p1
->
m_trs
);
case
M_SIZE
:
return
(
p2
->
m_size
-
p1
->
m_size
);
case
M_RESIDENT
:
return
(
p2
->
m_resident
-
p1
->
m_resident
);
case
M_SHARE
:
return
(
p2
->
m_share
-
p1
->
m_share
);
case
PERCENT_CPU
:
case
PERCENT_CPU
:
return
(
p2
->
percent_cpu
>
p1
->
percent_cpu
?
1
:
-
1
);
return
(
p2
->
percent_cpu
>
p1
->
percent_cpu
?
1
:
-
1
);
case
PERCENT_MEM
:
case
PERCENT_MEM
:
return
(
p2
->
m_resident
-
p1
->
m_resident
);
return
(
p2
->
m_resident
-
p1
->
m_resident
);
case
UTIME
:
diff
=
p2
->
utime
-
p1
->
utime
;
goto
test_diff
;
case
CUTIME
:
diff
=
p2
->
cutime
-
p1
->
cutime
;
goto
test_diff
;
case
STIME
:
diff
=
p2
->
stime
-
p1
->
stime
;
goto
test_diff
;
case
CSTIME
:
diff
=
p2
->
cstime
-
p2
->
cstime
;
goto
test_diff
;
case
TIME
:
return
((
p2
->
utime
+
p2
->
stime
)
-
(
p1
->
utime
+
p1
->
stime
));
case
COMM
:
case
COMM
:
return
strcmp
(
p1
->
comm
,
p2
->
comm
);
return
strcmp
(
p1
->
comm
,
p2
->
comm
);
case
MAJFLT
:
return
(
p2
->
majflt
-
p1
->
majflt
);
case
MINFLT
:
return
(
p2
->
minflt
-
p1
->
minflt
);
case
M_RESIDENT
:
return
(
p2
->
m_resident
-
p1
->
m_resident
);
case
M_SIZE
:
return
(
p2
->
m_size
-
p1
->
m_size
);
case
NICE
:
return
(
p1
->
nice
-
p2
->
nice
);
case
NLWP
:
case
NLWP
:
return
(
p1
->
nlwp
-
p2
->
nlwp
);
return
(
p1
->
nlwp
-
p2
->
nlwp
);
case
PGRP
:
return
(
p1
->
pgrp
-
p2
->
pgrp
);
case
PID
:
return
(
p1
->
pid
-
p2
->
pid
);
case
PPID
:
return
(
p1
->
ppid
-
p2
->
ppid
);
case
PRIORITY
:
return
(
p1
->
priority
-
p2
->
priority
);
case
SESSION
:
return
(
p1
->
session
-
p2
->
session
);
case
STARTTIME
:
{
case
STARTTIME
:
{
if
(
p1
->
starttime_ctime
==
p2
->
starttime_ctime
)
if
(
p1
->
starttime_ctime
==
p2
->
starttime_ctime
)
return
(
p1
->
pid
-
p2
->
pid
);
return
(
p1
->
pid
-
p2
->
pid
);
else
else
return
(
p1
->
starttime_ctime
-
p2
->
starttime_ctime
);
return
(
p1
->
starttime_ctime
-
p2
->
starttime_ctime
);
}
}
#ifdef HAVE_OPENVZ
case
STATE
:
case
CTID
:
return
(
p1
->
state
-
p2
->
state
);
return
(
p1
->
ctid
-
p2
->
ctid
);
case
ST_UID
:
case
VPID
:
return
(
p1
->
st_uid
-
p2
->
st_uid
);
return
(
p1
->
vpid
-
p2
->
vpid
);
case
TIME
:
#endif
return
((
p2
->
time
)
-
(
p1
->
time
));
#ifdef HAVE_VSERVER
case
TGID
:
case
VXID
:
return
(
p1
->
tgid
-
p2
->
tgid
);
return
(
p1
->
vxid
-
p2
->
vxid
);
case
TPGID
:
#endif
return
(
p1
->
tpgid
-
p2
->
tpgid
);
#ifdef HAVE_TASKSTATS
case
TTY_NR
:
case
RCHAR
:
diff
=
p2
->
io_rchar
-
p1
->
io_rchar
;
goto
test_diff
;
return
(
p1
->
tty_nr
-
p2
->
tty_nr
);
case
WCHAR
:
diff
=
p2
->
io_wchar
-
p1
->
io_wchar
;
goto
test_diff
;
case
USER
:
case
SYSCR
:
diff
=
p2
->
io_syscr
-
p1
->
io_syscr
;
goto
test_diff
;
return
strcmp
(
p1
->
user
?
p1
->
user
:
""
,
p2
->
user
?
p2
->
user
:
""
);
case
SYSCW
:
diff
=
p2
->
io_syscw
-
p1
->
io_syscw
;
goto
test_diff
;
case
RBYTES
:
diff
=
p2
->
io_read_bytes
-
p1
->
io_read_bytes
;
goto
test_diff
;
case
WBYTES
:
diff
=
p2
->
io_write_bytes
-
p1
->
io_write_bytes
;
goto
test_diff
;
case
CNCLWB
:
diff
=
p2
->
io_cancelled_write_bytes
-
p1
->
io_cancelled_write_bytes
;
goto
test_diff
;
case
IO_READ_RATE
:
diff
=
p2
->
io_rate_read_bps
-
p1
->
io_rate_read_bps
;
goto
test_diff
;
case
IO_WRITE_RATE
:
diff
=
p2
->
io_rate_write_bps
-
p1
->
io_rate_write_bps
;
goto
test_diff
;
case
IO_RATE
:
diff
=
(
p2
->
io_rate_read_bps
+
p2
->
io_rate_write_bps
)
-
(
p1
->
io_rate_read_bps
+
p1
->
io_rate_write_bps
);
goto
test_diff
;
#endif
#ifdef HAVE_CGROUP
case
CGROUP
:
return
strcmp
(
p1
->
cgroup
?
p1
->
cgroup
:
""
,
p2
->
cgroup
?
p2
->
cgroup
:
""
);
#endif
#ifdef HAVE_OOM
case
OOM
:
return
(
p1
->
oom
-
p2
->
oom
);
#endif
default:
default:
return
(
p1
->
pid
-
p2
->
pid
);
return
(
p1
->
pid
-
p2
->
pid
);
}
}
test_diff:
return
(
diff
>
0
)
?
1
:
(
diff
<
0
?
-
1
:
0
);
}
}
Process.h
View file @
40f3391a
...
@@ -22,26 +22,40 @@ in the source distribution for its full text.
...
@@ -22,26 +22,40 @@ in the source distribution for its full text.
#define PROCESS_FLAG_IO 0x0001
#define PROCESS_FLAG_IO 0x0001
#ifndef Process_isKernelThread
typedef
enum
ProcessFields
{
#define Process_isKernelThread(_process) (_process->pgrp == 0)
PID
=
1
,
#endif
COMM
=
2
,
STATE
=
3
,
#ifndef Process_isUserlandThread
PPID
=
4
,
#define Process_isUserlandThread(_process) (_process->pid != _process->tgid)
PGRP
=
5
,
#endif
SESSION
=
6
,
TTY_NR
=
7
,
#ifndef Process_isThread
TPGID
=
8
,
#define Process_isThread(_process) (Process_isUserlandThread(_process) || Process_isKernelThread(_process))
MINFLT
=
10
,
#endif
MAJFLT
=
12
,
PRIORITY
=
18
,
typedef
int
ProcessField
;
NICE
=
19
,
STARTTIME
=
21
,
M_SIZE
=
39
,
M_RESIDENT
=
40
,
ST_UID
=
46
,
PERCENT_CPU
=
47
,
PERCENT_MEM
=
48
,
USER
=
49
,
TIME
=
50
,
NLWP
=
51
,
TGID
=
52
,
}
ProcessField
;
typedef
struct
Process_
{
typedef
struct
Process_
{
Object
super
;
Object
super
;
struct
Settings_
*
settings
;
struct
Settings_
*
settings
;
unsigned
long
long
int
time
;
pid_t
pid
;
pid_t
pid
;
pid_t
ppid
;
pid_t
tgid
;
char
*
comm
;
char
*
comm
;
int
indent
;
int
indent
;
...
@@ -52,73 +66,30 @@ typedef struct Process_ {
...
@@ -52,73 +66,30 @@ typedef struct Process_ {
bool
tag
;
bool
tag
;
bool
showChildren
;
bool
showChildren
;
bool
show
;
bool
show
;
pid_t
ppid
;
unsigned
int
pgrp
;
unsigned
int
pgrp
;
unsigned
int
session
;
unsigned
int
session
;
unsigned
int
tty_nr
;
unsigned
int
tty_nr
;
pid_t
tgid
;
int
tpgid
;
int
tpgid
;
uid_t
st_uid
;
unsigned
long
int
flags
;
unsigned
long
int
flags
;
uid_t
st_uid
;
float
percent_cpu
;
float
percent_cpu
;
float
percent_mem
;
float
percent_mem
;
char
*
user
;
char
*
user
;
unsigned
long
long
int
utime
;
unsigned
long
long
int
stime
;
unsigned
long
long
int
cutime
;
unsigned
long
long
int
cstime
;
long
int
priority
;
long
int
priority
;
long
int
nice
;
long
int
nice
;
long
int
nlwp
;
long
int
nlwp
;
char
starttime_show
[
8
];
char
starttime_show
[
8
];
time_t
starttime_ctime
;
time_t
starttime_ctime
;
#ifdef HAVE_TASKSTATS
unsigned
long
long
io_rchar
;
unsigned
long
long
io_wchar
;
unsigned
long
long
io_syscr
;
unsigned
long
long
io_syscw
;
unsigned
long
long
io_read_bytes
;
unsigned
long
long
io_write_bytes
;
unsigned
long
long
io_cancelled_write_bytes
;
unsigned
long
long
io_rate_read_time
;
unsigned
long
long
io_rate_write_time
;
double
io_rate_read_bps
;
double
io_rate_write_bps
;
#endif
int
processor
;
long
m_size
;
long
m_size
;
long
m_resident
;
long
m_resident
;
long
m_share
;
long
m_trs
;
long
m_drs
;
long
m_lrs
;
long
m_dt
;
#ifdef HAVE_OPENVZ
unsigned
int
ctid
;
unsigned
int
vpid
;
#endif
#ifdef HAVE_VSERVER
unsigned
int
vxid
;
#endif
#ifdef HAVE_CGROUP
char
*
cgroup
;
#endif
#ifdef HAVE_OOM
unsigned
int
oom
;
#endif
int
exit_signal
;
int
exit_signal
;
unsigned
long
int
minflt
;
unsigned
long
int
minflt
;
unsigned
long
int
cminflt
;
unsigned
long
int
majflt
;
unsigned
long
int
majflt
;
unsigned
long
int
cmajflt
;
#ifdef DEBUG
#ifdef DEBUG
long
int
itrealvalue
;
long
int
itrealvalue
;
unsigned
long
int
vsize
;
unsigned
long
int
vsize
;
...
@@ -147,8 +118,15 @@ typedef struct ProcessFieldData_ {
...
@@ -147,8 +118,15 @@ typedef struct ProcessFieldData_ {
int
flags
;
int
flags
;
}
ProcessFieldData
;
}
ProcessFieldData
;
// Implemented in platform-specific code:
void
Process_setupColumnWidths
();
void
Process_writeField
(
Process
*
this
,
RichString
*
str
,
ProcessField
field
);
void
Process_writeField
(
Process
*
this
,
RichString
*
str
,
ProcessField
field
);
long
Process_compare
(
const
void
*
v1
,
const
void
*
v2
);
long
Process_compare
(
const
void
*
v1
,
const
void
*
v2
);
void
Process_delete
(
Object
*
cast
);
bool
Process_isThread
(
Process
*
this
);
extern
ProcessFieldData
Process_fields
[];
extern
char
*
Process_pidFormat
;
extern
char
*
Process_tpgidFormat
;
#define ONE_K 1024L
#define ONE_K 1024L
...
@@ -159,6 +137,14 @@ long Process_compare(const void* v1, const void* v2);
...
@@ -159,6 +137,14 @@ long Process_compare(const void* v1, const void* v2);
#define ONE_DECIMAL_M (ONE_DECIMAL_K * ONE_DECIMAL_K)
#define ONE_DECIMAL_M (ONE_DECIMAL_K * ONE_DECIMAL_K)
#define ONE_DECIMAL_G (ONE_DECIMAL_M * ONE_DECIMAL_K)
#define ONE_DECIMAL_G (ONE_DECIMAL_M * ONE_DECIMAL_K)
void
Process_humanNumber
(
RichString
*
str
,
unsigned
long
number
,
bool
coloring
);
void
Process_colorNumber
(
RichString
*
str
,
unsigned
long
long
number
,
bool
coloring
);
void
Process_printTime
(
RichString
*
str
,
unsigned
long
long
t
);
void
Process_outputRate
(
RichString
*
str
,
char
*
buffer
,
int
n
,
double
rate
,
int
coloring
);
void
Process_writeDefaultField
(
Process
*
this
,
RichString
*
str
,
ProcessField
field
);
void
Process_writeDefaultField
(
Process
*
this
,
RichString
*
str
,
ProcessField
field
);
void
Process_done
(
Process
*
this
);
void
Process_done
(
Process
*
this
);
...
...
Settings.c
View file @
40f3391a
...
@@ -65,10 +65,6 @@ typedef struct Settings_ {
...
@@ -65,10 +65,6 @@ typedef struct Settings_ {
}*/
}*/
static
ProcessField
defaultFields
[]
=
{
PID
,
USER
,
PRIORITY
,
NICE
,
M_SIZE
,
M_RESIDENT
,
M_SHARE
,
STATE
,
PERCENT_CPU
,
PERCENT_MEM
,
TIME
,
COMM
,
0
};
//static ProcessField defaultIoFields[] = { PID, IO_PRIORITY, USER, IO_READ_RATE, IO_WRITE_RATE, IO_RATE, COMM, 0 };
void
Settings_delete
(
Settings
*
this
)
{
void
Settings_delete
(
Settings
*
this
)
{
free
(
this
->
filename
);
free
(
this
->
filename
);
free
(
this
->
fields
);
free
(
this
->
fields
);
...
@@ -315,7 +311,7 @@ Settings* Settings_new(int cpuCount) {
...
@@ -315,7 +311,7 @@ Settings* Settings_new(int cpuCount) {
// TODO: turn 'fields' into a Vector,
// TODO: turn 'fields' into a Vector,
// (and ProcessFields into proper objects).
// (and ProcessFields into proper objects).
this
->
flags
=
0
;
this
->
flags
=
0
;
ProcessField
*
defaults
=
defaultFields
;
ProcessField
*
defaults
=
Platform_
defaultFields
;
for
(
int
i
=
0
;
defaults
[
i
];
i
++
)
{
for
(
int
i
=
0
;
defaults
[
i
];
i
++
)
{
this
->
fields
[
i
]
=
defaults
[
i
];
this
->
fields
[
i
]
=
defaults
[
i
];
this
->
flags
|=
Process_fields
[
defaults
[
i
]].
flags
;
this
->
flags
|=
Process_fields
[
defaults
[
i
]].
flags
;
...
...
linux/LinuxProcess.c
View file @
40f3391a
This diff is collapsed.
Click to expand it.
linux/LinuxProcess.h
View file @
40f3391a
...
@@ -15,28 +15,66 @@ in the source distribution for its full text.
...
@@ -15,28 +15,66 @@ in the source distribution for its full text.
#define PROCESS_FLAG_LINUX_VSERVER 0x0400
#define PROCESS_FLAG_LINUX_VSERVER 0x0400
#define PROCESS_FLAG_LINUX_CGROUP 0x0800
#define PROCESS_FLAG_LINUX_CGROUP 0x0800
typedef
enum
UnsupportedProcessFields
{
FLAGS
=
9
,
ITREALVALUE
=
20
,
VSIZE
=
22
,
RSS
=
23
,
RLIM
=
24
,
STARTCODE
=
25
,
ENDCODE
=
26
,
STARTSTACK
=
27
,
KSTKESP
=
28
,
KSTKEIP
=
29
,
SIGNAL
=
30
,
BLOCKED
=
31
,
SSIGIGNORE
=
32
,
SIGCATCH
=
33
,
WCHAN
=
34
,
NSWAP
=
35
,
CNSWAP
=
36
,
EXIT_SIGNAL
=
37
,
}
UnsupportedProcessField
;
typedef
enum
LinuxProcessFields
{
typedef
enum
LinuxProcessFields
{
PID
=
1
,
COMM
,
STATE
,
PPID
,
PGRP
,
SESSION
,
TTY_NR
,
TPGID
,
FLAGS
,
MINFLT
,
CMINFLT
,
MAJFLT
,
CMAJFLT
,
UTIME
,
CMINFLT
=
11
,
STIME
,
CUTIME
,
CSTIME
,
PRIORITY
,
NICE
,
ITREALVALUE
,
STARTTIME
,
VSIZE
,
RSS
,
RLIM
,
STARTCODE
,
ENDCODE
,
CMAJFLT
=
13
,
STARTSTACK
,
KSTKESP
,
KSTKEIP
,
SIGNAL
,
BLOCKED
,
SSIGIGNORE
,
SIGCATCH
,
WCHAN
,
NSWAP
,
CNSWAP
,
EXIT_SIGNAL
,
UTIME
=
14
,
PROCESSOR
,
M_SIZE
,
M_RESIDENT
,
M_SHARE
,
M_TRS
,
M_DRS
,
M_LRS
,
M_DT
,
ST_UID
,
PERCENT_CPU
,
PERCENT_MEM
,
STIME
=
15
,
USER
,
TIME
,
NLWP
,
TGID
,
CUTIME
=
16
,
CSTIME
=
17
,
PROCESSOR
=
38
,
M_SHARE
=
41
,
M_TRS
=
42
,
M_DRS
=
43
,
M_LRS
=
44
,
M_DT
=
45
,
#ifdef HAVE_OPENVZ
#ifdef HAVE_OPENVZ
CTID
,
VPID
,
CTID
=
100
,
VPID
=
101
,
#endif
#endif
#ifdef HAVE_VSERVER
#ifdef HAVE_VSERVER
VXID
,
VXID
=
102
,
#endif
#endif
#ifdef HAVE_TASKSTATS
#ifdef HAVE_TASKSTATS
RCHAR
,
WCHAR
,
SYSCR
,
SYSCW
,
RBYTES
,
WBYTES
,
CNCLWB
,
IO_READ_RATE
,
IO_WRITE_RATE
,
IO_RATE
,
RCHAR
=
103
,
WCHAR
=
104
,
SYSCR
=
105
,
SYSCW
=
106
,
RBYTES
=
107
,
WBYTES
=
108
,
CNCLWB
=
109
,
IO_READ_RATE
=
110
,
IO_WRITE_RATE
=
111
,
IO_RATE
=
112
,
#endif
#endif
#ifdef HAVE_CGROUP
#ifdef HAVE_CGROUP
CGROUP
,
CGROUP
=
113
,
#endif
#endif
#ifdef HAVE_OOM
#ifdef HAVE_OOM
OOM
,
OOM
=
114
,
#endif
#endif
IO_PRIORITY
,
IO_PRIORITY
=
115
,
LAST_PROCESSFIELD
LAST_PROCESSFIELD
}
LinuxProcessField
;
}
LinuxProcessField
;
...
@@ -45,9 +83,53 @@ typedef enum LinuxProcessFields {
...
@@ -45,9 +83,53 @@ typedef enum LinuxProcessFields {
typedef
struct
LinuxProcess_
{
typedef
struct
LinuxProcess_
{
Process
super
;
Process
super
;
IOPriority
ioPriority
;
IOPriority
ioPriority
;
unsigned
long
int
cminflt
;
unsigned
long
int
cmajflt
;
unsigned
long
long
int
utime
;
unsigned
long
long
int
stime
;
unsigned
long
long
int
cutime
;
unsigned
long
long
int
cstime
;
int
processor
;
long
m_share
;
long
m_trs
;
long
m_drs
;
long
m_lrs
;
long
m_dt
;
#ifdef HAVE_TASKSTATS
unsigned
long
long
io_rchar
;
unsigned
long
long
io_wchar
;
unsigned
long
long
io_syscr
;
unsigned
long
long
io_syscw
;
unsigned
long
long
io_read_bytes
;
unsigned
long
long
io_write_bytes
;
unsigned
long
long
io_cancelled_write_bytes
;
unsigned
long
long
io_rate_read_time
;
unsigned
long
long
io_rate_write_time
;
double
io_rate_read_bps
;
double
io_rate_write_bps
;
#endif
#ifdef HAVE_OPENVZ
unsigned
int
ctid
;
unsigned
int
vpid
;
#endif
#ifdef HAVE_VSERVER
unsigned
int
vxid
;
#endif
#ifdef HAVE_CGROUP
char
*
cgroup
;
#endif
#ifdef HAVE_OOM
unsigned
int
oom
;
#endif
}
LinuxProcess
;
}
LinuxProcess
;
#define Process_delete LinuxProcess_delete
#ifndef Process_isKernelThread
#define Process_isKernelThread(_process) (_process->pgrp == 0)
#endif
#ifndef Process_isUserlandThread
#define Process_isUserlandThread(_process) (_process->pid != _process->tgid)
#endif
extern
ProcessFieldData
Process_fields
[];
extern
ProcessFieldData
Process_fields
[];
...
@@ -59,7 +141,7 @@ void Process_setupColumnWidths();
...
@@ -59,7 +141,7 @@ void Process_setupColumnWidths();
LinuxProcess
*
LinuxProcess_new
(
Settings
*
settings
);
LinuxProcess
*
LinuxProcess_new
(
Settings
*
settings
);
void
Linux
Process_delete
(
Object
*
cast
);
void
Process_delete
(
Object
*
cast
);
/*
/*
[1] Note that before kernel 2.6.26 a process that has not asked for
[1] Note that before kernel 2.6.26 a process that has not asked for
...
@@ -79,4 +161,7 @@ void Process_writeField(Process* this, RichString* str, ProcessField field);
...
@@ -79,4 +161,7 @@ void Process_writeField(Process* this, RichString* str, ProcessField field);
long
Process_compare
(
const
void
*
v1
,
const
void
*
v2
);
long
Process_compare
(
const
void
*
v1
,
const
void
*
v2
);
bool
Process_isThread
(
Process
*
this
);
#endif
#endif
linux/LinuxProcessList.c
View file @
40f3391a
...
@@ -152,6 +152,7 @@ static ssize_t xread(int fd, void *buf, size_t count) {
...
@@ -152,6 +152,7 @@ static ssize_t xread(int fd, void *buf, size_t count) {
}
}
static
bool
LinuxProcessList_readStatFile
(
Process
*
process
,
const
char
*
dirname
,
const
char
*
name
,
char
*
command
)
{
static
bool
LinuxProcessList_readStatFile
(
Process
*
process
,
const
char
*
dirname
,
const
char
*
name
,
char
*
command
)
{
LinuxProcess
*
lp
=
(
LinuxProcess
*
)
process
;
char
filename
[
MAX_NAME
+
1
];
char
filename
[
MAX_NAME
+
1
];
snprintf
(
filename
,
MAX_NAME
,
"%s/%s/stat"
,
dirname
,
name
);
snprintf
(
filename
,
MAX_NAME
,
"%s/%s/stat"
,
dirname
,
name
);
int
fd
=
open
(
filename
,
O_RDONLY
);
int
fd
=
open
(
filename
,
O_RDONLY
);
...
@@ -194,19 +195,19 @@ static bool LinuxProcessList_readStatFile(Process *process, const char* dirname,
...
@@ -194,19 +195,19 @@ static bool LinuxProcessList_readStatFile(Process *process, const char* dirname,
location
+=
1
;
location
+=
1
;
process
->
minflt
=
strtoull
(
location
,
&
location
,
10
);
process
->
minflt
=
strtoull
(
location
,
&
location
,
10
);
location
+=
1
;
location
+=
1
;
p
rocess
->
cminflt
=
strtoull
(
location
,
&
location
,
10
);
l
p
->
cminflt
=
strtoull
(
location
,
&
location
,
10
);
location
+=
1
;
location
+=
1
;
process
->
majflt
=
strtoull
(
location
,
&
location
,
10
);
process
->
majflt
=
strtoull
(
location
,
&
location
,
10
);
location
+=
1
;
location
+=
1
;
p
rocess
->
cmajflt
=
strtoull
(
location
,
&
location
,
10
);
l
p
->
cmajflt
=
strtoull
(
location
,
&
location
,
10
);
location
+=
1
;
location
+=
1
;
p
rocess
->
utime
=
strtoull
(
location
,
&
location
,
10
);
l
p
->
utime
=
strtoull
(
location
,
&
location
,
10
);
location
+=
1
;
location
+=
1
;
p
rocess
->
stime
=
strtoull
(
location
,
&
location
,
10
);
l
p
->
stime
=
strtoull
(
location
,
&
location
,
10
);
location
+=
1
;
location
+=
1
;
p
rocess
->
cutime
=
strtoull
(
location
,
&
location
,
10
);
l
p
->
cutime
=
strtoull
(
location
,
&
location
,
10
);
location
+=
1
;
location
+=
1
;
p
rocess
->
cstime
=
strtoull
(
location
,
&
location
,
10
);
l
p
->
cstime
=
strtoull
(
location
,
&
location
,
10
);
location
+=
1
;
location
+=
1
;
process
->
priority
=
strtol
(
location
,
&
location
,
10
);
process
->
priority
=
strtol
(
location
,
&
location
,
10
);
location
+=
1
;
location
+=
1
;
...
@@ -218,7 +219,9 @@ static bool LinuxProcessList_readStatFile(Process *process, const char* dirname,
...
@@ -218,7 +219,9 @@ static bool LinuxProcessList_readStatFile(Process *process, const char* dirname,
process
->
exit_signal
=
strtol
(
location
,
&
location
,
10
);
process
->
exit_signal
=
strtol
(
location
,
&
location
,
10
);
location
+=
1
;
location
+=
1
;
assert
(
location
!=
NULL
);
assert
(
location
!=
NULL
);
process
->
processor
=
strtol
(
location
,
&
location
,
10
);
lp
->
processor
=
strtol
(
location
,
&
location
,
10
);
process
->
time
=
lp
->
utime
+
lp
->
stime
;
return
true
;
return
true
;
}
}
...
@@ -246,7 +249,7 @@ static bool LinuxProcessList_statProcessDir(Process* process, const char* dirnam
...
@@ -246,7 +249,7 @@ static bool LinuxProcessList_statProcessDir(Process* process, const char* dirnam
#ifdef HAVE_TASKSTATS
#ifdef HAVE_TASKSTATS
static
void
LinuxProcessList_readIoFile
(
Process
*
process
,
const
char
*
dirname
,
char
*
name
,
unsigned
long
long
now
)
{
static
void
LinuxProcessList_readIoFile
(
Linux
Process
*
process
,
const
char
*
dirname
,
char
*
name
,
unsigned
long
long
now
)
{
char
filename
[
MAX_NAME
+
1
];
char
filename
[
MAX_NAME
+
1
];
filename
[
MAX_NAME
]
=
'\0'
;
filename
[
MAX_NAME
]
=
'\0'
;
...
@@ -307,7 +310,7 @@ static void LinuxProcessList_readIoFile(Process* process, const char* dirname, c
...
@@ -307,7 +310,7 @@ static void LinuxProcessList_readIoFile(Process* process, const char* dirname, c
static
bool
LinuxProcessList_readStatmFile
(
Process
*
process
,
const
char
*
dirname
,
const
char
*
name
)
{
static
bool
LinuxProcessList_readStatmFile
(
Linux
Process
*
process
,
const
char
*
dirname
,
const
char
*
name
)
{
char
filename
[
MAX_NAME
+
1
];
char
filename
[
MAX_NAME
+
1
];
snprintf
(
filename
,
MAX_NAME
,
"%s/%s/statm"
,
dirname
,
name
);
snprintf
(
filename
,
MAX_NAME
,
"%s/%s/statm"
,
dirname
,
name
);
int
fd
=
open
(
filename
,
O_RDONLY
);
int
fd
=
open
(
filename
,
O_RDONLY
);
...
@@ -320,8 +323,8 @@ static bool LinuxProcessList_readStatmFile(Process* process, const char* dirname
...
@@ -320,8 +323,8 @@ static bool LinuxProcessList_readStatmFile(Process* process, const char* dirname
char
*
p
=
buf
;
char
*
p
=
buf
;
errno
=
0
;
errno
=
0
;
process
->
m_size
=
strtol
(
p
,
&
p
,
10
);
if
(
*
p
==
' '
)
p
++
;
process
->
super
.
m_size
=
strtol
(
p
,
&
p
,
10
);
if
(
*
p
==
' '
)
p
++
;
process
->
m_resident
=
strtol
(
p
,
&
p
,
10
);
if
(
*
p
==
' '
)
p
++
;
process
->
super
.
m_resident
=
strtol
(
p
,
&
p
,
10
);
if
(
*
p
==
' '
)
p
++
;
process
->
m_share
=
strtol
(
p
,
&
p
,
10
);
if
(
*
p
==
' '
)
p
++
;
process
->
m_share
=
strtol
(
p
,
&
p
,
10
);
if
(
*
p
==
' '
)
p
++
;
process
->
m_trs
=
strtol
(
p
,
&
p
,
10
);
if
(
*
p
==
' '
)
p
++
;
process
->
m_trs
=
strtol
(
p
,
&
p
,
10
);
if
(
*
p
==
' '
)
p
++
;
process
->
m_lrs
=
strtol
(
p
,
&
p
,
10
);
if
(
*
p
==
' '
)
p
++
;
process
->
m_lrs
=
strtol
(
p
,
&
p
,
10
);
if
(
*
p
==
' '
)
p
++
;
...
@@ -360,7 +363,7 @@ static void LinuxProcessList_readOpenVZData(ProcessList* this, Process* process,
...
@@ -360,7 +363,7 @@ static void LinuxProcessList_readOpenVZData(ProcessList* this, Process* process,
#ifdef HAVE_CGROUP
#ifdef HAVE_CGROUP
static
void
LinuxProcessList_readCGroupFile
(
Process
*
process
,
const
char
*
dirname
,
const
char
*
name
)
{
static
void
LinuxProcessList_readCGroupFile
(
Linux
Process
*
process
,
const
char
*
dirname
,
const
char
*
name
)
{
char
filename
[
MAX_NAME
+
1
];
char
filename
[
MAX_NAME
+
1
];
snprintf
(
filename
,
MAX_NAME
,
"%s/%s/cgroup"
,
dirname
,
name
);
snprintf
(
filename
,
MAX_NAME
,
"%s/%s/cgroup"
,
dirname
,
name
);
FILE
*
file
=
fopen
(
filename
,
"r"
);
FILE
*
file
=
fopen
(
filename
,
"r"
);
...
@@ -390,7 +393,7 @@ static void LinuxProcessList_readCGroupFile(Process* process, const char* dirnam
...
@@ -390,7 +393,7 @@ static void LinuxProcessList_readCGroupFile(Process* process, const char* dirnam
#ifdef HAVE_VSERVER
#ifdef HAVE_VSERVER
static
void
LinuxProcessList_readVServerData
(
Process
*
process
,
const
char
*
dirname
,
const
char
*
name
)
{
static
void
LinuxProcessList_readVServerData
(
Linux
Process
*
process
,
const
char
*
dirname
,
const
char
*
name
)
{
char
filename
[
MAX_NAME
+
1
];
char
filename
[
MAX_NAME
+
1
];
snprintf
(
filename
,
MAX_NAME
,
"%s/%s/status"
,
dirname
,
name
);
snprintf
(
filename
,
MAX_NAME
,
"%s/%s/status"
,
dirname
,
name
);
FILE
*
file
=
fopen
(
filename
,
"r"
);
FILE
*
file
=
fopen
(
filename
,
"r"
);
...
@@ -423,7 +426,7 @@ static void LinuxProcessList_readVServerData(Process* process, const char* dirna
...
@@ -423,7 +426,7 @@ static void LinuxProcessList_readVServerData(Process* process, const char* dirna
#ifdef HAVE_OOM
#ifdef HAVE_OOM
static
void
LinuxProcessList_readOomData
(
Process
*
process
,
const
char
*
dirname
,
const
char
*
name
)
{
static
void
LinuxProcessList_readOomData
(
Linux
Process
*
process
,
const
char
*
dirname
,
const
char
*
name
)
{
char
filename
[
MAX_NAME
+
1
];
char
filename
[
MAX_NAME
+
1
];
snprintf
(
filename
,
MAX_NAME
,
"%s/%s/oom_score"
,
dirname
,
name
);
snprintf
(
filename
,
MAX_NAME
,
"%s/%s/oom_score"
,
dirname
,
name
);
FILE
*
file
=
fopen
(
filename
,
"r"
);
FILE
*
file
=
fopen
(
filename
,
"r"
);
...
@@ -514,95 +517,97 @@ static bool LinuxProcessList_processEntries(LinuxProcessList* this, const char*
...
@@ -514,95 +517,97 @@ static bool LinuxProcessList_processEntries(LinuxProcessList* this, const char*
if
(
pid
<=
0
)
if
(
pid
<=
0
)
continue
;
continue
;
Process
*
proc
ess
=
NULL
;
Process
*
proc
=
NULL
;
Process
*
existingProc
ess
=
(
Process
*
)
Hashtable_get
(
this
->
super
.
processTable
,
pid
);
Process
*
existingProc
=
(
Process
*
)
Hashtable_get
(
this
->
super
.
processTable
,
pid
);
if
(
existingProc
ess
)
{
if
(
existingProc
)
{
assert
(
Vector_indexOf
(
this
->
processes
,
existingProc
ess
,
Process_pidCompare
)
!=
-
1
);
assert
(
Vector_indexOf
(
this
->
processes
,
existingProc
,
Process_pidCompare
)
!=
-
1
);
proc
ess
=
existingProc
ess
;
proc
=
existingProc
;
assert
(
proc
ess
->
pid
==
pid
);
assert
(
proc
->
pid
==
pid
);
}
else
{
}
else
{
proc
ess
=
(
Process
*
)
LinuxProcess_new
(
settings
);
proc
=
(
Process
*
)
LinuxProcess_new
(
settings
);
assert
(
proc
ess
->
comm
==
NULL
);
assert
(
proc
->
comm
==
NULL
);
proc
ess
->
pid
=
pid
;
proc
->
pid
=
pid
;
proc
ess
->
tgid
=
parent
?
parent
->
pid
:
pid
;
proc
->
tgid
=
parent
?
parent
->
pid
:
pid
;
}
}
LinuxProcess
*
lp
=
(
LinuxProcess
*
)
proc
;
char
subdirname
[
MAX_NAME
+
1
];
char
subdirname
[
MAX_NAME
+
1
];
snprintf
(
subdirname
,
MAX_NAME
,
"%s/%s/task"
,
dirname
,
name
);
snprintf
(
subdirname
,
MAX_NAME
,
"%s/%s/task"
,
dirname
,
name
);
LinuxProcessList_processEntries
(
this
,
subdirname
,
proc
ess
,
period
,
tv
);
LinuxProcessList_processEntries
(
this
,
subdirname
,
proc
,
period
,
tv
);
#ifdef HAVE_TASKSTATS
#ifdef HAVE_TASKSTATS
if
(
settings
->
flags
&
PROCESS_FLAG_IO
)
if
(
settings
->
flags
&
PROCESS_FLAG_IO
)
LinuxProcessList_readIoFile
(
p
rocess
,
dirname
,
name
,
now
);
LinuxProcessList_readIoFile
(
l
p
,
dirname
,
name
,
now
);
#endif
#endif
if
(
!
LinuxProcessList_readStatmFile
(
p
rocess
,
dirname
,
name
))
if
(
!
LinuxProcessList_readStatmFile
(
l
p
,
dirname
,
name
))
goto
errorReadingProcess
;
goto
errorReadingProcess
;
proc
ess
->
show
=
!
((
hideKernelThreads
&&
Process_isKernelThread
(
proc
ess
))
||
(
hideUserlandThreads
&&
Process_isUserlandThread
(
proc
ess
)));
proc
->
show
=
!
((
hideKernelThreads
&&
Process_isKernelThread
(
proc
))
||
(
hideUserlandThreads
&&
Process_isUserlandThread
(
proc
)));
char
command
[
MAX_NAME
+
1
];
char
command
[
MAX_NAME
+
1
];
unsigned
long
long
int
lasttimes
=
(
p
rocess
->
utime
+
p
rocess
->
stime
);
unsigned
long
long
int
lasttimes
=
(
l
p
->
utime
+
l
p
->
stime
);
if
(
!
LinuxProcessList_readStatFile
(
proc
ess
,
dirname
,
name
,
command
))
if
(
!
LinuxProcessList_readStatFile
(
proc
,
dirname
,
name
,
command
))
goto
errorReadingProcess
;
goto
errorReadingProcess
;
if
(
settings
->
flags
&
PROCESS_FLAG_LINUX_IOPRIO
)
if
(
settings
->
flags
&
PROCESS_FLAG_LINUX_IOPRIO
)
LinuxProcess_updateIOPriority
(
(
LinuxProcess
*
)
process
);
LinuxProcess_updateIOPriority
(
lp
);
float
percent_cpu
=
(
p
rocess
->
utime
+
p
rocess
->
stime
-
lasttimes
)
/
period
*
100
.
0
;
float
percent_cpu
=
(
l
p
->
utime
+
l
p
->
stime
-
lasttimes
)
/
period
*
100
.
0
;
proc
ess
->
percent_cpu
=
MAX
(
MIN
(
percent_cpu
,
cpus
*
100
.
0
),
0
.
0
);
proc
->
percent_cpu
=
MAX
(
MIN
(
percent_cpu
,
cpus
*
100
.
0
),
0
.
0
);
if
(
isnan
(
proc
ess
->
percent_cpu
))
proc
ess
->
percent_cpu
=
0
.
0
;
if
(
isnan
(
proc
->
percent_cpu
))
proc
->
percent_cpu
=
0
.
0
;
proc
ess
->
percent_mem
=
(
proc
ess
->
m_resident
*
PAGE_SIZE_KB
)
/
(
double
)(
this
->
totalMem
)
*
100
.
0
;
proc
->
percent_mem
=
(
proc
->
m_resident
*
PAGE_SIZE_KB
)
/
(
double
)(
this
->
totalMem
)
*
100
.
0
;
if
(
!
existingProc
ess
)
{
if
(
!
existingProc
)
{
if
(
!
LinuxProcessList_statProcessDir
(
proc
ess
,
dirname
,
name
,
curTime
))
if
(
!
LinuxProcessList_statProcessDir
(
proc
,
dirname
,
name
,
curTime
))
goto
errorReadingProcess
;
goto
errorReadingProcess
;
proc
ess
->
user
=
UsersTable_getRef
(
this
->
super
.
usersTable
,
proc
ess
->
st_uid
);
proc
->
user
=
UsersTable_getRef
(
this
->
super
.
usersTable
,
proc
->
st_uid
);
#ifdef HAVE_OPENVZ
#ifdef HAVE_OPENVZ
LinuxProcessList_readOpenVZData
(
this
,
p
rocess
,
dirname
,
name
);
LinuxProcessList_readOpenVZData
(
this
,
l
p
,
dirname
,
name
);
#endif
#endif
#ifdef HAVE_VSERVER
#ifdef HAVE_VSERVER
if
(
settings
->
flags
&
PROCESS_FLAG_LINUX_VSERVER
)
if
(
settings
->
flags
&
PROCESS_FLAG_LINUX_VSERVER
)
LinuxProcessList_readVServerData
(
p
rocess
,
dirname
,
name
);
LinuxProcessList_readVServerData
(
l
p
,
dirname
,
name
);
#endif
#endif
if
(
!
LinuxProcessList_readCmdlineFile
(
proc
ess
,
dirname
,
name
))
if
(
!
LinuxProcessList_readCmdlineFile
(
proc
,
dirname
,
name
))
goto
errorReadingProcess
;
goto
errorReadingProcess
;
ProcessList_add
((
ProcessList
*
)
this
,
proc
ess
);
ProcessList_add
((
ProcessList
*
)
this
,
proc
);
}
else
{
}
else
{
if
(
settings
->
updateProcessNames
)
{
if
(
settings
->
updateProcessNames
)
{
if
(
!
LinuxProcessList_readCmdlineFile
(
proc
ess
,
dirname
,
name
))
if
(
!
LinuxProcessList_readCmdlineFile
(
proc
,
dirname
,
name
))
goto
errorReadingProcess
;
goto
errorReadingProcess
;
}
}
}
}
#ifdef HAVE_CGROUP
#ifdef HAVE_CGROUP
if
(
settings
->
flags
&
PROCESS_FLAG_LINUX_CGROUP
)
if
(
settings
->
flags
&
PROCESS_FLAG_LINUX_CGROUP
)
LinuxProcessList_readCGroupFile
(
p
rocess
,
dirname
,
name
);
LinuxProcessList_readCGroupFile
(
l
p
,
dirname
,
name
);
#endif
#endif
#ifdef HAVE_OOM
#ifdef HAVE_OOM
LinuxProcessList_readOomData
(
p
rocess
,
dirname
,
name
);
LinuxProcessList_readOomData
(
l
p
,
dirname
,
name
);
#endif
#endif
if
(
proc
ess
->
state
==
'Z'
)
{
if
(
proc
->
state
==
'Z'
)
{
free
(
proc
ess
->
comm
);
free
(
proc
->
comm
);
proc
ess
->
basenameOffset
=
-
1
;
proc
->
basenameOffset
=
-
1
;
proc
ess
->
comm
=
strdup
(
command
);
proc
->
comm
=
strdup
(
command
);
}
else
if
(
Process_isThread
(
proc
ess
))
{
}
else
if
(
Process_isThread
(
proc
))
{
if
(
settings
->
showThreadNames
||
Process_isKernelThread
(
proc
ess
)
||
proc
ess
->
state
==
'Z'
)
{
if
(
settings
->
showThreadNames
||
Process_isKernelThread
(
proc
)
||
proc
->
state
==
'Z'
)
{
free
(
proc
ess
->
comm
);
free
(
proc
->
comm
);
proc
ess
->
basenameOffset
=
-
1
;
proc
->
basenameOffset
=
-
1
;
proc
ess
->
comm
=
strdup
(
command
);
proc
->
comm
=
strdup
(
command
);
}
else
if
(
settings
->
showThreadNames
)
{
}
else
if
(
settings
->
showThreadNames
)
{
if
(
!
LinuxProcessList_readCmdlineFile
(
proc
ess
,
dirname
,
name
))
if
(
!
LinuxProcessList_readCmdlineFile
(
proc
,
dirname
,
name
))
goto
errorReadingProcess
;
goto
errorReadingProcess
;
}
}
if
(
Process_isKernelThread
(
proc
ess
))
{
if
(
Process_isKernelThread
(
proc
))
{
this
->
kernelThreads
++
;
this
->
kernelThreads
++
;
}
else
{
}
else
{
this
->
userlandThreads
++
;
this
->
userlandThreads
++
;
...
@@ -610,23 +615,23 @@ static bool LinuxProcessList_processEntries(LinuxProcessList* this, const char*
...
@@ -610,23 +615,23 @@ static bool LinuxProcessList_processEntries(LinuxProcessList* this, const char*
}
}
this
->
totalTasks
++
;
this
->
totalTasks
++
;
if
(
proc
ess
->
state
==
'R'
)
if
(
proc
->
state
==
'R'
)
this
->
runningTasks
++
;
this
->
runningTasks
++
;
proc
ess
->
updated
=
true
;
proc
->
updated
=
true
;
continue
;
continue
;
// Exception handler.
// Exception handler.
errorReadingProcess:
{
errorReadingProcess:
{
if
(
proc
ess
->
comm
)
{
if
(
proc
->
comm
)
{
free
(
proc
ess
->
comm
);
free
(
proc
->
comm
);
proc
ess
->
basenameOffset
=
-
1
;
proc
->
basenameOffset
=
-
1
;
proc
ess
->
comm
=
NULL
;
proc
->
comm
=
NULL
;
}
}
if
(
existingProc
ess
)
if
(
existingProc
)
ProcessList_remove
((
ProcessList
*
)
this
,
proc
ess
);
ProcessList_remove
((
ProcessList
*
)
this
,
proc
);
else
else
Linux
Process_delete
((
Object
*
)
proc
ess
);
Process_delete
((
Object
*
)
proc
);
}
}
}
}
closedir
(
dir
);
closedir
(
dir
);
...
...
linux/Platform.c
View file @
40f3391a
...
@@ -21,6 +21,7 @@ in the source distribution for its full text.
...
@@ -21,6 +21,7 @@ in the source distribution for its full text.
#include "UptimeMeter.h"
#include "UptimeMeter.h"
#include "ClockMeter.h"
#include "ClockMeter.h"
#include "HostnameMeter.h"
#include "HostnameMeter.h"
#include "LinuxProcess.h"
#include <math.h>
#include <math.h>
#include <assert.h>
#include <assert.h>
...
@@ -29,10 +30,12 @@ in the source distribution for its full text.
...
@@ -29,10 +30,12 @@ in the source distribution for its full text.
#include "Action.h"
#include "Action.h"
#include "MainPanel.h"
#include "MainPanel.h"
#include "BatteryMeter.h"
#include "BatteryMeter.h"
#include "LinuxProcess.h"
}*/
}*/
ProcessField
Platform_defaultFields
[]
=
{
PID
,
USER
,
PRIORITY
,
NICE
,
M_SIZE
,
M_RESIDENT
,
M_SHARE
,
STATE
,
PERCENT_CPU
,
PERCENT_MEM
,
TIME
,
COMM
,
0
};
//static ProcessField defaultIoFields[] = { PID, IO_PRIORITY, USER, IO_READ_RATE, IO_WRITE_RATE, IO_RATE, COMM, 0 };
int
Platform_numberOfFields
=
LAST_PROCESSFIELD
;
int
Platform_numberOfFields
=
LAST_PROCESSFIELD
;
static
Htop_Reaction
Platform_actionSetIOPriority
(
State
*
st
)
{
static
Htop_Reaction
Platform_actionSetIOPriority
(
State
*
st
)
{
...
...
linux/Platform.h
View file @
40f3391a
...
@@ -12,8 +12,8 @@ in the source distribution for its full text.
...
@@ -12,8 +12,8 @@ in the source distribution for its full text.
#include "Action.h"
#include "Action.h"
#include "MainPanel.h"
#include "MainPanel.h"
#include "BatteryMeter.h"
#include "BatteryMeter.h"
#include "LinuxProcess.h"
extern
ProcessField
Platform_defaultFields
[];
extern
int
Platform_numberOfFields
;
extern
int
Platform_numberOfFields
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment