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
e6c6d7fb
Commit
e6c6d7fb
authored
Aug 10, 2012
by
Hisham Muhammad
Browse files
Add -p flag, contributed by Rob Hoelz
parent
6c71b7ed
Changes
5
Hide whitespace changes
Inline
Side-by-side
Panel.c
View file @
e6c6d7fb
...
...
@@ -250,7 +250,11 @@ void Panel_draw(Panel* this, bool focus) {
int
scrollH
=
this
->
scrollH
;
int
y
=
this
->
y
;
int
x
=
this
->
x
;
int
first
=
this
->
scrollV
;
int
last
=
MIN
(
itemCount
,
this
->
scrollV
+
MIN
(
itemCount
,
this
->
h
));
if
(
itemCount
>
this
->
h
&&
first
>
itemCount
-
this
->
h
)
{
first
=
itemCount
-
this
->
h
;
this
->
scrollV
=
first
;
}
int
last
=
MIN
(
itemCount
,
first
+
MIN
(
itemCount
,
this
->
h
));
if
(
this
->
selected
<
first
)
{
first
=
this
->
selected
;
this
->
scrollV
=
first
;
...
...
ProcessList.c
View file @
e6c6d7fb
...
...
@@ -114,6 +114,7 @@ typedef struct ProcessList_ {
uid_t userId;
bool filtering;
const char* incFilter;
Hashtable* pidWhiteList;
int cpuCount;
int totalTasks;
...
...
@@ -180,12 +181,13 @@ const char *ProcessList_treeStrUtf8[TREE_STR_COUNT] = {
"
\xe2\x94\x80
"
,
// TREE_STR_SHUT ─
};
ProcessList
*
ProcessList_new
(
UsersTable
*
usersTable
)
{
ProcessList
*
ProcessList_new
(
UsersTable
*
usersTable
,
Hashtable
*
pidWhiteList
)
{
ProcessList
*
this
;
this
=
calloc
(
sizeof
(
ProcessList
),
1
);
this
->
processes
=
Vector_new
(
PROCESS_CLASS
,
true
,
DEFAULT_SIZE
,
Process_compare
);
this
->
processTable
=
Hashtable_new
(
140
,
false
);
this
->
usersTable
=
usersTable
;
this
->
pidWhiteList
=
pidWhiteList
;
/* tree-view auxiliary buffers */
this
->
processes2
=
Vector_new
(
PROCESS_CLASS
,
true
,
DEFAULT_SIZE
,
Process_compare
);
...
...
@@ -599,6 +601,7 @@ static void ProcessList_readVServerData(Process* process, const char* dirname, c
static
bool
ProcessList_readCmdlineFile
(
Process
*
process
,
const
char
*
dirname
,
const
char
*
name
)
{
if
(
Process_isKernelThread
(
process
))
return
true
;
char
filename
[
MAX_NAME
+
1
];
snprintf
(
filename
,
MAX_NAME
,
"%s/%s/cmdline"
,
dirname
,
name
);
FILE
*
file
=
fopen
(
filename
,
"r"
);
...
...
@@ -617,6 +620,7 @@ static bool ProcessList_readCmdlineFile(Process* process, const char* dirname, c
fclose
(
file
);
free
(
process
->
comm
);
process
->
comm
=
strdup
(
command
);
return
true
;
}
...
...
@@ -928,7 +932,8 @@ void ProcessList_rebuildPanel(ProcessList* this, bool flags, int following, bool
if
(
(
!
p
->
show
)
||
(
userOnly
&&
(
p
->
st_uid
!=
userId
))
||
(
filtering
&&
!
(
String_contains_i
(
p
->
comm
,
incFilter
)))
)
||
(
filtering
&&
!
(
String_contains_i
(
p
->
comm
,
incFilter
)))
||
(
this
->
pidWhiteList
&&
!
Hashtable_get
(
this
->
pidWhiteList
,
p
->
pid
))
)
hidden
=
true
;
if
(
!
hidden
)
{
...
...
ProcessList.h
View file @
e6c6d7fb
...
...
@@ -97,6 +97,7 @@ typedef struct ProcessList_ {
uid_t
userId
;
bool
filtering
;
const
char
*
incFilter
;
Hashtable
*
pidWhiteList
;
int
cpuCount
;
int
totalTasks
;
...
...
@@ -144,7 +145,7 @@ extern const char *ProcessList_treeStrAscii[TREE_STR_COUNT];
extern
const
char
*
ProcessList_treeStrUtf8
[
TREE_STR_COUNT
];
ProcessList
*
ProcessList_new
(
UsersTable
*
usersTable
);
ProcessList
*
ProcessList_new
(
UsersTable
*
usersTable
,
Hashtable
*
pidWhiteList
);
void
ProcessList_delete
(
ProcessList
*
this
);
...
...
htop.1.in
View file @
e6c6d7fb
...
...
@@ -29,12 +29,15 @@ Start htop in monochrome mode
\fB\-h \-\-help
Display a help message and exit
.TP
\fB\-
u
\-\-
user=USERNAME
\fR
Show only the
processes of a
given
user
\fB\-
p
\-\-
pid=PID,PID...
\fR
Show only the given
PIDs
.TP
\fB\-s \-\-sort\-key COLUMN\fR
Sort by this column (use \-\-sort\-key help for a column list)
.TP
\fB\-u \-\-user=USERNAME\fR
Show only the processes of a given user
.TP
\fB\-v \-\-version
Output version information and exit
.PP
...
...
htop.c
View file @
e6c6d7fb
...
...
@@ -51,11 +51,12 @@ static void printVersionFlag() {
static
void
printHelpFlag
()
{
fputs
(
"htop "
VERSION
" - "
COPYRIGHT
"
\n
"
"Released under the GNU GPL.
\n\n
"
"-C --no-color Use a monochrome color scheme
\n
"
"-d --delay=DELAY Set the delay between updates, in tenths of seconds
\n
"
"-h --help Print this help screen
\n
"
"-s --sort-key=COLUMN Sort by COLUMN (try --sort-key=help for a list)
\n
"
"-u --user=USERNAME Show only processes of a given user
\n
"
"-C --no-color Use a monochrome color scheme
\n
"
"-d --delay=DELAY Set the delay between updates, in tenths of seconds
\n
"
"-h --help Print this help screen
\n
"
"-s --sort-key=COLUMN Sort by COLUMN (try --sort-key=help for a list)
\n
"
"-u --user=USERNAME Show only processes of a given user
\n
"
"-p --pid=PID,[,PID,PID...] Show only the given PIDs
\n
"
"-v --version Print version info
\n
"
"
\n
"
"Long options may be passed with a single dash.
\n\n
"
...
...
@@ -269,6 +270,9 @@ int main(int argc, char** argv) {
uid_t
userId
=
0
;
int
usecolors
=
1
;
TreeType
treeType
=
TREE_TYPE_AUTO
;
char
*
argCopy
;
char
*
pid
;
Hashtable
*
pidWhiteList
=
NULL
;
int
opt
,
opti
=
0
;
static
struct
option
long_opts
[]
=
...
...
@@ -280,6 +284,7 @@ int main(int argc, char** argv) {
{
"user"
,
required_argument
,
0
,
'u'
},
{
"no-color"
,
no_argument
,
0
,
'C'
},
{
"no-colour"
,
no_argument
,
0
,
'C'
},
{
"pid"
,
required_argument
,
0
,
'p'
},
{
0
,
0
,
0
,
0
}
};
int
sortKey
=
0
;
...
...
@@ -293,7 +298,7 @@ int main(int argc, char** argv) {
setlocale
(
LC_CTYPE
,
""
);
/* Parse arguments */
while
((
opt
=
getopt_long
(
argc
,
argv
,
"hvCs:d:u:"
,
long_opts
,
&
opti
)))
{
while
((
opt
=
getopt_long
(
argc
,
argv
,
"hvCs:d:u:
p:
"
,
long_opts
,
&
opti
)))
{
if
(
opt
==
EOF
)
break
;
switch
(
opt
)
{
case
'h'
:
...
...
@@ -332,6 +337,22 @@ int main(int argc, char** argv) {
break
;
case
'C'
:
usecolors
=
0
;
break
;
case
'p'
:
argCopy
=
strdup
(
optarg
);
pid
=
strtok
(
argCopy
,
","
);
if
(
!
pidWhiteList
)
{
pidWhiteList
=
Hashtable_new
(
8
,
false
);
}
while
(
pid
)
{
unsigned
int
num_pid
=
atoi
(
pid
);
Hashtable_put
(
pidWhiteList
,
num_pid
,
(
void
*
)
1
);
pid
=
strtok
(
NULL
,
","
);
}
free
(
argCopy
);
break
;
default:
exit
(
1
);
...
...
@@ -356,7 +377,7 @@ int main(int argc, char** argv) {
ProcessList
*
pl
=
NULL
;
UsersTable
*
ut
=
UsersTable_new
();
pl
=
ProcessList_new
(
ut
);
pl
=
ProcessList_new
(
ut
,
pidWhiteList
);
Process_getMaxPid
();
Header
*
header
=
Header_new
(
pl
);
...
...
@@ -936,5 +957,8 @@ int main(int argc, char** argv) {
((
Object
*
)
killPanel
)
->
delete
((
Object
*
)
killPanel
);
UsersTable_delete
(
ut
);
Settings_delete
(
settings
);
if
(
pidWhiteList
)
{
Hashtable_delete
(
pidWhiteList
);
}
return
0
;
}
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