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
75080ce7
Commit
75080ce7
authored
Sep 29, 2011
by
Hisham Muhammad
Browse files
Use wider PID columns in 64-bit machines with larger pid_max values.
parent
d25a0bc2
Changes
3
Hide whitespace changes
Inline
Side-by-side
Process.c
View file @
75080ce7
...
...
@@ -202,14 +202,14 @@ const char *Process_fieldNames[] = {
};
const
char
*
Process_fieldTitles
[]
=
{
""
,
" PID "
,
"Command "
,
"S "
,
" PPID "
,
" PGRP "
,
" SESN "
,
" TTY "
,
"TPGID "
,
"- "
,
"- "
,
"- "
,
"- "
,
"- "
,
""
,
"
PID "
,
"Command "
,
"S "
,
"
PPID "
,
" PGRP "
,
" SESN "
,
" TTY "
,
"
TPGID "
,
"- "
,
"- "
,
"- "
,
"- "
,
"- "
,
" UTIME+ "
,
" STIME+ "
,
" CUTIME+ "
,
" CSTIME+ "
,
"PRI "
,
" NI "
,
"- "
,
"START "
,
"- "
,
"- "
,
"- "
,
"- "
,
"- "
,
"- "
,
"- "
,
"- "
,
"- "
,
"- "
,
"- "
,
"- "
,
"- "
,
"- "
,
"- "
,
"- "
,
"CPU "
,
" VIRT "
,
" RES "
,
" SHR "
,
" CODE "
,
" DATA "
,
" LIB "
,
" DIRTY "
,
" UID "
,
"CPU% "
,
"MEM% "
,
"USER "
,
" TIME+ "
,
"NLWP "
,
" TGID "
,
"USER "
,
" TIME+ "
,
"NLWP "
,
"
TGID "
,
#ifdef HAVE_OPENVZ
" CTID "
,
" VPID "
,
#endif
...
...
@@ -217,7 +217,7 @@ const char *Process_fieldTitles[] = {
" VXID "
,
#endif
#ifdef HAVE_TASKSTATS
" RD_CHAR "
,
" WR_CHAR "
,
" RD_SYSC "
,
" WR_SYSC "
,
" IO_RBYTES "
,
" IO_WBYTES "
,
" IO_CANCEL "
,
"
RD_CHAR "
,
"
WR_CHAR "
,
" RD_SYSC "
,
" WR_SYSC "
,
" IO_RBYTES "
,
" IO_WBYTES "
,
" IO_CANCEL "
,
" IORR "
,
" IOWR "
,
" IO "
,
#endif
#ifdef HAVE_CGROUP
...
...
@@ -228,6 +228,32 @@ const char *Process_fieldTitles[] = {
static
int
Process_getuid
=
-
1
;
static
char
*
Process_pidFormat
=
"%7u "
;
static
char
*
Process_tpgidFormat
=
"%7u "
;
void
Process_getMaxPid
()
{
FILE
*
file
=
fopen
(
PROCDIR
"/sys/kernel/pid_max"
,
"r"
);
if
(
!
file
)
return
;
int
maxPid
=
4194303
;
fscanf
(
file
,
"%d"
,
&
maxPid
);
fclose
(
file
);
if
(
maxPid
>
99999
)
{
Process_fieldTitles
[
PID
]
=
" PID "
;
Process_fieldTitles
[
PPID
]
=
" PPID "
;
Process_fieldTitles
[
TPGID
]
=
" TPGID "
;
Process_fieldTitles
[
TGID
]
=
" TGID "
;
Process_pidFormat
=
"%7u "
;
Process_tpgidFormat
=
"%7d "
;
}
else
{
Process_fieldTitles
[
PID
]
=
" PID "
;
Process_fieldTitles
[
PPID
]
=
" PPID "
;
Process_fieldTitles
[
TPGID
]
=
"TPGID "
;
Process_fieldTitles
[
TGID
]
=
" TGID "
;
Process_pidFormat
=
"%5u "
;
Process_tpgidFormat
=
"%5d "
;
}
}
#define ONE_K 1024
#define ONE_M (ONE_K * ONE_K)
#define ONE_G (ONE_M * ONE_K)
...
...
@@ -341,13 +367,13 @@ static void Process_writeField(Process* this, RichString* str, ProcessField fiel
int
n
=
sizeof
(
buffer
)
-
1
;
switch
(
field
)
{
case
PID
:
snprintf
(
buffer
,
n
,
"%5u "
,
this
->
pid
);
break
;
case
PPID
:
snprintf
(
buffer
,
n
,
"%5u "
,
this
->
ppid
);
break
;
case
PID
:
snprintf
(
buffer
,
n
,
Process_pidFormat
,
this
->
pid
);
break
;
case
PPID
:
snprintf
(
buffer
,
n
,
Process_pidFormat
,
this
->
ppid
);
break
;
case
PGRP
:
snprintf
(
buffer
,
n
,
"%5u "
,
this
->
pgrp
);
break
;
case
SESSION
:
snprintf
(
buffer
,
n
,
"%5u "
,
this
->
session
);
break
;
case
TTY_NR
:
snprintf
(
buffer
,
n
,
"%5u "
,
this
->
tty_nr
);
break
;
case
TGID
:
snprintf
(
buffer
,
n
,
"%5u "
,
this
->
tgid
);
break
;
case
TPGID
:
snprintf
(
buffer
,
n
,
"%5d "
,
this
->
tpgid
);
break
;
case
TGID
:
snprintf
(
buffer
,
n
,
Process_pidFormat
,
this
->
tgid
);
break
;
case
TPGID
:
snprintf
(
buffer
,
n
,
Process_tpgidFormat
,
this
->
tpgid
);
break
;
case
PROCESSOR
:
snprintf
(
buffer
,
n
,
"%3d "
,
ProcessList_cpuId
(
this
->
pl
,
this
->
processor
));
break
;
case
NLWP
:
snprintf
(
buffer
,
n
,
"%4ld "
,
this
->
nlwp
);
break
;
case
COMM
:
{
...
...
@@ -456,8 +482,8 @@ static void Process_writeField(Process* this, RichString* str, ProcessField fiel
case
VXID
:
snprintf
(
buffer
,
n
,
"%5u "
,
this
->
vxid
);
break
;
#endif
#ifdef HAVE_TASKSTATS
case
RCHAR
:
snprintf
(
buffer
,
n
,
"%1
0
llu "
,
this
->
io_rchar
);
break
;
case
WCHAR
:
snprintf
(
buffer
,
n
,
"%1
0
llu "
,
this
->
io_wchar
);
break
;
case
RCHAR
:
snprintf
(
buffer
,
n
,
"%1
2
llu "
,
this
->
io_rchar
);
break
;
case
WCHAR
:
snprintf
(
buffer
,
n
,
"%1
2
llu "
,
this
->
io_wchar
);
break
;
case
SYSCR
:
snprintf
(
buffer
,
n
,
"%10llu "
,
this
->
io_syscr
);
break
;
case
SYSCW
:
snprintf
(
buffer
,
n
,
"%10llu "
,
this
->
io_syscw
);
break
;
case
RBYTES
:
Process_colorNumber
(
this
,
str
,
this
->
io_read_bytes
);
return
;
...
...
Process.h
View file @
75080ce7
...
...
@@ -181,6 +181,9 @@ extern const char *Process_fieldNames[];
extern
const
char
*
Process_fieldTitles
[];
void
Process_getMaxPid
();
#define ONE_K 1024
#define ONE_M (ONE_K * ONE_K)
#define ONE_G (ONE_M * ONE_K)
...
...
htop.c
View file @
75080ce7
...
...
@@ -350,6 +350,7 @@ int main(int argc, char** argv) {
UsersTable
*
ut
=
UsersTable_new
();
pl
=
ProcessList_new
(
ut
);
Process_getMaxPid
();
Header
*
header
=
Header_new
(
pl
);
settings
=
Settings_new
(
pl
,
header
);
...
...
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