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
cf7fdcd1
Commit
cf7fdcd1
authored
Dec 17, 2007
by
Hisham Muhammad
Browse files
Experimental feature: beep on permission failures.
Update dates.
parent
a839c3f2
Changes
3
Hide whitespace changes
Inline
Side-by-side
Process.c
View file @
cf7fdcd1
...
@@ -42,7 +42,7 @@ typedef enum ProcessField_ {
...
@@ -42,7 +42,7 @@ typedef enum ProcessField_ {
STIME, CUTIME, CSTIME, PRIORITY, NICE, ITREALVALUE, STARTTIME, VSIZE, RSS, RLIM, STARTCODE, ENDCODE,
STIME, CUTIME, CSTIME, PRIORITY, NICE, ITREALVALUE, STARTTIME, VSIZE, RSS, RLIM, STARTCODE, ENDCODE,
STARTSTACK, KSTKESP, KSTKEIP, SIGNAL, BLOCKED, SSIGIGNORE, SIGCATCH, WCHAN, NSWAP, CNSWAP, EXIT_SIGNAL,
STARTSTACK, KSTKESP, KSTKEIP, SIGNAL, BLOCKED, SSIGIGNORE, SIGCATCH, WCHAN, NSWAP, CNSWAP, EXIT_SIGNAL,
PROCESSOR, M_SIZE, M_RESIDENT, M_SHARE, M_TRS, M_DRS, M_LRS, M_DT, ST_UID, PERCENT_CPU, PERCENT_MEM,
PROCESSOR, M_SIZE, M_RESIDENT, M_SHARE, M_TRS, M_DRS, M_LRS, M_DT, ST_UID, PERCENT_CPU, PERCENT_MEM,
USER, TIME, NLWP, TGID
USER, TIME, NLWP, TGID
,
#ifdef HAVE_OPENVZ
#ifdef HAVE_OPENVZ
VEID, VPID,
VEID, VPID,
#endif
#endif
...
@@ -187,12 +187,13 @@ void Process_toggleTag(Process* this) {
...
@@ -187,12 +187,13 @@ void Process_toggleTag(Process* this) {
this
->
tag
=
this
->
tag
==
true
?
false
:
true
;
this
->
tag
=
this
->
tag
==
true
?
false
:
true
;
}
}
void
Process_setPriority
(
Process
*
this
,
int
priority
)
{
bool
Process_setPriority
(
Process
*
this
,
int
priority
)
{
int
old_prio
=
getpriority
(
PRIO_PROCESS
,
this
->
pid
);
int
old_prio
=
getpriority
(
PRIO_PROCESS
,
this
->
pid
);
int
err
=
setpriority
(
PRIO_PROCESS
,
this
->
pid
,
priority
);
int
err
=
setpriority
(
PRIO_PROCESS
,
this
->
pid
,
priority
);
if
(
err
==
0
&&
old_prio
!=
getpriority
(
PRIO_PROCESS
,
this
->
pid
))
{
if
(
err
==
0
&&
old_prio
!=
getpriority
(
PRIO_PROCESS
,
this
->
pid
))
{
this
->
nice
=
priority
;
this
->
nice
=
priority
;
}
}
return
(
err
==
0
);
}
}
unsigned
long
Process_getAffinity
(
Process
*
this
)
{
unsigned
long
Process_getAffinity
(
Process
*
this
)
{
...
@@ -201,8 +202,8 @@ unsigned long Process_getAffinity(Process* this) {
...
@@ -201,8 +202,8 @@ unsigned long Process_getAffinity(Process* this) {
return
mask
;
return
mask
;
}
}
void
Process_setAffinity
(
Process
*
this
,
unsigned
long
mask
)
{
bool
Process_setAffinity
(
Process
*
this
,
unsigned
long
mask
)
{
sched_setaffinity
(
this
->
pid
,
sizeof
(
unsigned
long
),
(
cpu_set_t
*
)
&
mask
);
return
(
sched_setaffinity
(
this
->
pid
,
sizeof
(
unsigned
long
),
(
cpu_set_t
*
)
&
mask
)
==
0
)
;
}
}
void
Process_sendSignal
(
Process
*
this
,
int
signal
)
{
void
Process_sendSignal
(
Process
*
this
,
int
signal
)
{
...
...
Process.h
View file @
cf7fdcd1
...
@@ -141,11 +141,11 @@ void Process_display(Object* cast, RichString* out);
...
@@ -141,11 +141,11 @@ void Process_display(Object* cast, RichString* out);
void
Process_toggleTag
(
Process
*
this
);
void
Process_toggleTag
(
Process
*
this
);
void
Process_setPriority
(
Process
*
this
,
int
priority
);
bool
Process_setPriority
(
Process
*
this
,
int
priority
);
unsigned
long
Process_getAffinity
(
Process
*
this
);
unsigned
long
Process_getAffinity
(
Process
*
this
);
void
Process_setAffinity
(
Process
*
this
,
unsigned
long
mask
);
bool
Process_setAffinity
(
Process
*
this
,
unsigned
long
mask
);
void
Process_sendSignal
(
Process
*
this
,
int
signal
);
void
Process_sendSignal
(
Process
*
this
,
int
signal
);
...
...
htop.c
View file @
cf7fdcd1
/*
/*
htop - htop.c
htop - htop.c
(C) 2004-200
6
Hisham H. Muhammad
(C) 2004-200
7
Hisham H. Muhammad
Released under the GNU GPL, see the COPYING file
Released under the GNU GPL, see the COPYING file
in the source distribution for its full text.
in the source distribution for its full text.
*/
*/
...
@@ -36,14 +36,14 @@ in the source distribution for its full text.
...
@@ -36,14 +36,14 @@ in the source distribution for its full text.
void
printVersionFlag
()
{
void
printVersionFlag
()
{
clear
();
clear
();
printf
(
"htop "
VERSION
" - (C) 2004-200
6
Hisham Muhammad.
\n
"
);
printf
(
"htop "
VERSION
" - (C) 2004-200
7
Hisham Muhammad.
\n
"
);
printf
(
"Released under the GNU GPL.
\n\n
"
);
printf
(
"Released under the GNU GPL.
\n\n
"
);
exit
(
0
);
exit
(
0
);
}
}
void
printHelpFlag
()
{
void
printHelpFlag
()
{
clear
();
clear
();
printf
(
"htop "
VERSION
" - (C) 2004-200
6
Hisham Muhammad.
\n
"
);
printf
(
"htop "
VERSION
" - (C) 2004-200
7
Hisham Muhammad.
\n
"
);
printf
(
"Released under the GNU GPL.
\n\n
"
);
printf
(
"Released under the GNU GPL.
\n\n
"
);
printf
(
"-d DELAY Delay between updates, in tenths of seconds
\n\n
"
);
printf
(
"-d DELAY Delay between updates, in tenths of seconds
\n\n
"
);
printf
(
"-u USERNAME Show only processes of a given user
\n\n
"
);
printf
(
"-u USERNAME Show only processes of a given user
\n\n
"
);
...
@@ -56,7 +56,7 @@ void printHelpFlag() {
...
@@ -56,7 +56,7 @@ void printHelpFlag() {
void
showHelp
(
ProcessList
*
pl
)
{
void
showHelp
(
ProcessList
*
pl
)
{
clear
();
clear
();
attrset
(
CRT_colors
[
HELP_BOLD
]);
attrset
(
CRT_colors
[
HELP_BOLD
]);
mvaddstr
(
0
,
0
,
"htop "
VERSION
" - (C) 2004-200
6
Hisham Muhammad."
);
mvaddstr
(
0
,
0
,
"htop "
VERSION
" - (C) 2004-200
7
Hisham Muhammad."
);
mvaddstr
(
1
,
0
,
"Released under the GNU GPL. See 'man' page for more info."
);
mvaddstr
(
1
,
0
,
"Released under the GNU GPL. See 'man' page for more info."
);
attrset
(
CRT_colors
[
DEFAULT_COLOR
]);
attrset
(
CRT_colors
[
DEFAULT_COLOR
]);
...
@@ -151,18 +151,21 @@ static void Setup_run(Settings* settings, int headerHeight) {
...
@@ -151,18 +151,21 @@ static void Setup_run(Settings* settings, int headerHeight) {
}
}
static
bool
changePriority
(
Panel
*
panel
,
int
delta
)
{
static
bool
changePriority
(
Panel
*
panel
,
int
delta
)
{
bool
ok
=
true
;
bool
anyTagged
=
false
;
bool
anyTagged
=
false
;
for
(
int
i
=
0
;
i
<
Panel_getSize
(
panel
);
i
++
)
{
for
(
int
i
=
0
;
i
<
Panel_getSize
(
panel
);
i
++
)
{
Process
*
p
=
(
Process
*
)
Panel_get
(
panel
,
i
);
Process
*
p
=
(
Process
*
)
Panel_get
(
panel
,
i
);
if
(
p
->
tag
)
{
if
(
p
->
tag
)
{
Process_setPriority
(
p
,
p
->
nice
+
delta
);
ok
=
Process_setPriority
(
p
,
p
->
nice
+
delta
)
&&
ok
;
anyTagged
=
true
;
anyTagged
=
true
;
}
}
}
}
if
(
!
anyTagged
)
{
if
(
!
anyTagged
)
{
Process
*
p
=
(
Process
*
)
Panel_getSelected
(
panel
);
Process
*
p
=
(
Process
*
)
Panel_getSelected
(
panel
);
Process_setPriority
(
p
,
p
->
nice
+
delta
);
ok
=
Process_setPriority
(
p
,
p
->
nice
+
delta
)
&&
ok
;
}
}
if
(
!
ok
)
beep
();
return
anyTagged
;
return
anyTagged
;
}
}
...
@@ -608,20 +611,25 @@ int main(int argc, char** argv) {
...
@@ -608,20 +611,25 @@ int main(int argc, char** argv) {
Panel
*
affinityPanel
=
AffinityPanel_new
(
pl
->
processorCount
,
curr
);
Panel
*
affinityPanel
=
AffinityPanel_new
(
pl
->
processorCount
,
curr
);
char
*
fuFunctions
[
2
]
=
{
"Toggle "
,
"Done "
};
char
*
fuFunctions
[
2
]
=
{
"Set "
,
"Cancel "
};
pickFromList
(
panel
,
affinityPanel
,
15
,
headerHeight
,
fuFunctions
,
defaultBar
);
void
*
set
=
pickFromList
(
panel
,
affinityPanel
,
15
,
headerHeight
,
fuFunctions
,
defaultBar
);
unsigned
long
new
=
AffinityPanel_getAffinity
(
affinityPanel
);
if
(
set
)
{
bool
anyTagged
=
false
;
unsigned
long
new
=
AffinityPanel_getAffinity
(
affinityPanel
);
for
(
int
i
=
0
;
i
<
Panel_getSize
(
panel
);
i
++
)
{
bool
anyTagged
=
false
;
Process
*
p
=
(
Process
*
)
Panel_get
(
panel
,
i
);
bool
ok
=
true
;
if
(
p
->
tag
)
{
for
(
int
i
=
0
;
i
<
Panel_getSize
(
panel
);
i
++
)
{
Process_setAffinity
(
p
,
new
);
Process
*
p
=
(
Process
*
)
Panel_get
(
panel
,
i
);
anyTagged
=
true
;
if
(
p
->
tag
)
{
ok
=
Process_setAffinity
(
p
,
new
)
&&
ok
;
anyTagged
=
true
;
}
}
}
}
if
(
!
anyTagged
)
{
if
(
!
anyTagged
)
{
Process
*
p
=
(
Process
*
)
Panel_getSelected
(
panel
);
Process
*
p
=
(
Process
*
)
Panel_getSelected
(
panel
);
ok
=
Process_setAffinity
(
p
,
new
)
&&
ok
;
Process_setAffinity
(
p
,
new
);
}
if
(
!
ok
)
beep
();
}
}
((
Object
*
)
affinityPanel
)
->
delete
((
Object
*
)
affinityPanel
);
((
Object
*
)
affinityPanel
)
->
delete
((
Object
*
)
affinityPanel
);
Panel_setRichHeader
(
panel
,
ProcessList_printHeader
(
pl
));
Panel_setRichHeader
(
panel
,
ProcessList_printHeader
(
pl
));
...
...
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