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
6f868b00
Commit
6f868b00
authored
Feb 20, 2015
by
Hisham Muhammad
Browse files
Fix allocation of processes. Closes #166.
parent
f97d1bc5
Changes
9
Hide whitespace changes
Inline
Side-by-side
Process.c
View file @
6f868b00
...
@@ -647,14 +647,12 @@ static void Process_display(Object* cast, RichString* out) {
...
@@ -647,14 +647,12 @@ static void Process_display(Object* cast, RichString* out) {
assert
(
out
->
chlen
>
0
);
assert
(
out
->
chlen
>
0
);
}
}
void
Process_delete
(
Object
*
cast
)
{
void
Process_done
(
Process
*
this
)
{
Process
*
this
=
(
Process
*
)
cast
;
assert
(
this
!=
NULL
);
assert
(
this
!=
NULL
);
free
(
this
->
comm
);
free
(
this
->
comm
);
#ifdef HAVE_CGROUP
#ifdef HAVE_CGROUP
free
(
this
->
cgroup
);
free
(
this
->
cgroup
);
#endif
#endif
free
(
this
);
}
}
ObjectClass
Process_class
=
{
ObjectClass
Process_class
=
{
...
@@ -664,9 +662,7 @@ ObjectClass Process_class = {
...
@@ -664,9 +662,7 @@ ObjectClass Process_class = {
.
compare
=
Process_compare
.
compare
=
Process_compare
};
};
Process
*
Process_new
(
struct
Settings_
*
settings
)
{
void
Process_init
(
Process
*
this
,
struct
Settings_
*
settings
)
{
Process
*
this
=
calloc
(
1
,
sizeof
(
Process
));
Object_setClass
(
this
,
Class
(
Process
));
this
->
pid
=
0
;
this
->
pid
=
0
;
this
->
settings
=
settings
;
this
->
settings
=
settings
;
this
->
tag
=
false
;
this
->
tag
=
false
;
...
@@ -682,7 +678,6 @@ Process* Process_new(struct Settings_* settings) {
...
@@ -682,7 +678,6 @@ Process* Process_new(struct Settings_* settings) {
this
->
cgroup
=
NULL
;
this
->
cgroup
=
NULL
;
#endif
#endif
if
(
Process_getuid
==
-
1
)
Process_getuid
=
getuid
();
if
(
Process_getuid
==
-
1
)
Process_getuid
=
getuid
();
return
this
;
}
}
void
Process_toggleTag
(
Process
*
this
)
{
void
Process_toggleTag
(
Process
*
this
)
{
...
...
Process.h
View file @
6f868b00
...
@@ -191,11 +191,11 @@ void Process_setupColumnWidths();
...
@@ -191,11 +191,11 @@ void Process_setupColumnWidths();
void
Process_writeDefaultField
(
Process
*
this
,
RichString
*
str
,
ProcessField
field
);
void
Process_writeDefaultField
(
Process
*
this
,
RichString
*
str
,
ProcessField
field
);
void
Process_d
elete
(
Object
*
cast
);
void
Process_d
one
(
Process
*
this
);
extern
ObjectClass
Process_class
;
extern
ObjectClass
Process_class
;
Process
*
Process
_new
(
struct
Settings_
*
settings
);
void
Process
_init
(
Process
*
this
,
struct
Settings_
*
settings
);
void
Process_toggleTag
(
Process
*
this
);
void
Process_toggleTag
(
Process
*
this
);
...
...
ProcessList.c
View file @
6f868b00
...
@@ -241,7 +241,6 @@ void ProcessList_expandTree(ProcessList* this) {
...
@@ -241,7 +241,6 @@ void ProcessList_expandTree(ProcessList* this) {
}
}
void
ProcessList_rebuildPanel
(
ProcessList
*
this
)
{
void
ProcessList_rebuildPanel
(
ProcessList
*
this
)
{
int
following
=
this
->
following
;
const
char
*
incFilter
=
this
->
incFilter
;
const
char
*
incFilter
=
this
->
incFilter
;
int
currPos
=
Panel_getSelectedIndex
(
this
->
panel
);
int
currPos
=
Panel_getSelectedIndex
(
this
->
panel
);
...
...
ScreenManager.c
View file @
6f868b00
...
@@ -158,26 +158,20 @@ void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) {
...
@@ -158,26 +158,20 @@ void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) {
double
newTime
=
((
double
)
tv
.
tv_sec
*
10
)
+
((
double
)
tv
.
tv_usec
/
100000
);
double
newTime
=
((
double
)
tv
.
tv_sec
*
10
)
+
((
double
)
tv
.
tv_usec
/
100000
);
timeToRecalculate
=
(
newTime
-
oldTime
>
this
->
settings
->
delay
);
timeToRecalculate
=
(
newTime
-
oldTime
>
this
->
settings
->
delay
);
if
(
newTime
<
oldTime
)
timeToRecalculate
=
true
;
// clock was adjusted?
if
(
newTime
<
oldTime
)
timeToRecalculate
=
true
;
// clock was adjusted?
//fprintf(stderr, "\n%p %f ", this, newTime);
if
(
doRefresh
)
{
if
(
doRefresh
)
{
if
(
timeToRecalculate
||
forceRecalculate
)
{
if
(
timeToRecalculate
||
forceRecalculate
)
{
ProcessList_scan
(
this
->
header
->
pl
);
ProcessList_scan
(
this
->
header
->
pl
);
//fprintf(stderr, "scan ");
}
}
//fprintf(stderr, "sortTo=%d ", sortTimeout);
if
(
sortTimeout
==
0
||
this
->
settings
->
treeView
)
{
if
(
sortTimeout
==
0
||
this
->
settings
->
treeView
)
{
ProcessList_sort
(
this
->
header
->
pl
);
ProcessList_sort
(
this
->
header
->
pl
);
//fprintf(stderr, "sort ");
sortTimeout
=
1
;
sortTimeout
=
1
;
}
}
//this->header->pl->incFilter = IncSet_filter(inc);
//this->header->pl->incFilter = IncSet_filter(inc);
ProcessList_rebuildPanel
(
this
->
header
->
pl
);
ProcessList_rebuildPanel
(
this
->
header
->
pl
);
//fprintf(stderr, "rebuild ");
drawPanel
=
true
;
drawPanel
=
true
;
}
}
if
(
timeToRecalculate
||
forceRecalculate
)
{
if
(
timeToRecalculate
||
forceRecalculate
)
{
Header_draw
(
this
->
header
);
Header_draw
(
this
->
header
);
//fprintf(stderr, "drawHeader ");
oldTime
=
newTime
;
oldTime
=
newTime
;
forceRecalculate
=
false
;
forceRecalculate
=
false
;
}
}
...
@@ -188,7 +182,6 @@ void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) {
...
@@ -188,7 +182,6 @@ void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) {
for
(
int
i
=
0
;
i
<
panels
;
i
++
)
{
for
(
int
i
=
0
;
i
<
panels
;
i
++
)
{
Panel
*
panel
=
(
Panel
*
)
Vector_get
(
this
->
panels
,
i
);
Panel
*
panel
=
(
Panel
*
)
Vector_get
(
this
->
panels
,
i
);
Panel_draw
(
panel
,
i
==
focus
);
Panel_draw
(
panel
,
i
==
focus
);
//fprintf(stderr, "drawPanel ");
if
(
i
<
panels
)
{
if
(
i
<
panels
)
{
if
(
this
->
orientation
==
HORIZONTAL
)
{
if
(
this
->
orientation
==
HORIZONTAL
)
{
mvvline
(
panel
->
y
,
panel
->
x
+
panel
->
w
,
' '
,
panel
->
h
+
1
);
mvvline
(
panel
->
y
,
panel
->
x
+
panel
->
w
,
' '
,
panel
->
h
+
1
);
...
@@ -206,8 +199,6 @@ void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) {
...
@@ -206,8 +199,6 @@ void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) {
int
prevCh
=
ch
;
int
prevCh
=
ch
;
ch
=
getch
();
ch
=
getch
();
//fprintf(stderr, "ch=%d ", ch);
if
(
ch
==
KEY_MOUSE
)
{
if
(
ch
==
KEY_MOUSE
)
{
MEVENT
mevent
;
MEVENT
mevent
;
int
ok
=
getmouse
(
&
mevent
);
int
ok
=
getmouse
(
&
mevent
);
...
@@ -260,7 +251,6 @@ void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) {
...
@@ -260,7 +251,6 @@ void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) {
}
else
}
else
closeTimeout
=
0
;
closeTimeout
=
0
;
drawPanel
=
false
;
drawPanel
=
false
;
//fprintf(stderr, "err ");
continue
;
continue
;
}
}
drawPanel
=
true
;
drawPanel
=
true
;
...
@@ -300,12 +290,10 @@ void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) {
...
@@ -300,12 +290,10 @@ void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) {
quit
=
true
;
quit
=
true
;
continue
;
continue
;
default:
default:
//fprintf(stderr, "onKey ");
sortTimeout
=
resetSortTimeout
;
sortTimeout
=
resetSortTimeout
;
Panel_onKey
(
panelFocus
,
ch
);
Panel_onKey
(
panelFocus
,
ch
);
break
;
break
;
}
}
//fprintf(stderr, "loop ");
}
}
if
(
lastFocus
)
if
(
lastFocus
)
...
...
linux/LinuxProcess.c
View file @
6f868b00
...
@@ -10,6 +10,7 @@ in the source distribution for its full text.
...
@@ -10,6 +10,7 @@ in the source distribution for its full text.
#include "LinuxProcess.h"
#include "LinuxProcess.h"
#include "CRT.h"
#include "CRT.h"
#include <stdlib.h>
#include <unistd.h>
#include <unistd.h>
#include <sys/syscall.h>
#include <sys/syscall.h>
...
@@ -22,8 +23,23 @@ typedef struct LinuxProcess_ {
...
@@ -22,8 +23,23 @@ typedef struct LinuxProcess_ {
IOPriority ioPriority;
IOPriority ioPriority;
} LinuxProcess;
} LinuxProcess;
#define Process_delete LinuxProcess_delete
}*/
}*/
LinuxProcess
*
LinuxProcess_new
(
Settings
*
settings
)
{
LinuxProcess
*
this
=
calloc
(
sizeof
(
LinuxProcess
),
1
);
Process_init
(
&
this
->
super
,
settings
);
return
this
;
}
void
LinuxProcess_delete
(
Object
*
cast
)
{
LinuxProcess
*
this
=
(
LinuxProcess
*
)
this
;
Object_setClass
(
this
,
Class
(
Process
));
Process_done
((
Process
*
)
cast
);
free
(
this
);
}
/*
/*
[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
an io priority formally uses "none" as scheduling class, but the
an io priority formally uses "none" as scheduling class, but the
...
...
linux/LinuxProcess.h
View file @
6f868b00
...
@@ -17,6 +17,12 @@ typedef struct LinuxProcess_ {
...
@@ -17,6 +17,12 @@ typedef struct LinuxProcess_ {
IOPriority
ioPriority
;
IOPriority
ioPriority
;
}
LinuxProcess
;
}
LinuxProcess
;
#define Process_delete LinuxProcess_delete
LinuxProcess
*
LinuxProcess_new
(
Settings
*
settings
);
void
LinuxProcess_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
...
...
linux/LinuxProcessList.c
View file @
6f868b00
...
@@ -375,6 +375,7 @@ static void LinuxProcessList_readCGroupFile(Process* process, const char* dirnam
...
@@ -375,6 +375,7 @@ static void LinuxProcessList_readCGroupFile(Process* process, const char* dirnam
int
nFields
;
int
nFields
;
char
**
fields
=
String_split
(
trimmed
,
':'
,
&
nFields
);
char
**
fields
=
String_split
(
trimmed
,
':'
,
&
nFields
);
free
(
trimmed
);
free
(
trimmed
);
free
(
process
->
cgroup
);
if
(
nFields
>=
3
)
{
if
(
nFields
>=
3
)
{
process
->
cgroup
=
strndup
(
fields
[
2
]
+
1
,
10
);
process
->
cgroup
=
strndup
(
fields
[
2
]
+
1
,
10
);
}
else
{
}
else
{
...
@@ -521,7 +522,7 @@ static bool LinuxProcessList_processEntries(LinuxProcessList* this, const char*
...
@@ -521,7 +522,7 @@ static bool LinuxProcessList_processEntries(LinuxProcessList* this, const char*
process
=
existingProcess
;
process
=
existingProcess
;
assert
(
process
->
pid
==
pid
);
assert
(
process
->
pid
==
pid
);
}
else
{
}
else
{
process
=
Process_new
(
settings
);
process
=
(
Process
*
)
Linux
Process_new
(
settings
);
assert
(
process
->
comm
==
NULL
);
assert
(
process
->
comm
==
NULL
);
process
->
pid
=
pid
;
process
->
pid
=
pid
;
process
->
tgid
=
parent
?
parent
->
pid
:
pid
;
process
->
tgid
=
parent
?
parent
->
pid
:
pid
;
...
@@ -625,7 +626,7 @@ static bool LinuxProcessList_processEntries(LinuxProcessList* this, const char*
...
@@ -625,7 +626,7 @@ static bool LinuxProcessList_processEntries(LinuxProcessList* this, const char*
if
(
existingProcess
)
if
(
existingProcess
)
ProcessList_remove
((
ProcessList
*
)
this
,
process
);
ProcessList_remove
((
ProcessList
*
)
this
,
process
);
else
else
Process_delete
((
Object
*
)
process
);
Linux
Process_delete
((
Object
*
)
process
);
}
}
}
}
closedir
(
dir
);
closedir
(
dir
);
...
...
linux/Platform.c
View file @
6f868b00
...
@@ -29,6 +29,7 @@ in the source distribution for its full text.
...
@@ -29,6 +29,7 @@ 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"
}*/
}*/
static
Htop_Reaction
Platform_actionSetIOPriority
(
State
*
st
)
{
static
Htop_Reaction
Platform_actionSetIOPriority
(
State
*
st
)
{
...
...
linux/Platform.h
View file @
6f868b00
...
@@ -12,6 +12,7 @@ in the source distribution for its full text.
...
@@ -12,6 +12,7 @@ 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"
void
Platform_setBindings
(
Htop_Action
*
keys
);
void
Platform_setBindings
(
Htop_Action
*
keys
);
...
...
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