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
eb2803ce
Commit
eb2803ce
authored
Jul 12, 2006
by
Hisham Muhammad
Browse files
Share name strings from UsersList
parent
dbe2670b
Changes
3
Hide whitespace changes
Inline
Side-by-side
Process.c
View file @
eb2803ce
...
...
@@ -31,7 +31,6 @@ in the source distribution for its full text.
#define PAGE_SIZE ( sysconf(_SC_PAGESIZE) / 1024 )
#define PROCESS_COMM_LEN 300
#define PROCESS_USER_LEN 10
/*{
...
...
@@ -105,7 +104,7 @@ typedef struct Process_ {
uid_t st_uid;
float percent_cpu;
float percent_mem;
char user
[PROCESS_USER_LEN + 1]
;
char
*
user;
} Process;
}*/
...
...
@@ -120,6 +119,8 @@ char *Process_fieldNames[] = {
""
,
"PID"
,
"Command"
,
"STATE"
,
"PPID"
,
"PGRP"
,
"SESSION"
,
"TTY_NR"
,
"TPGID"
,
"FLAGS"
,
"MINFLT"
,
"CMINFLT"
,
"MAJFLT"
,
"CMAJFLT"
,
"UTIME"
,
"STIME"
,
"CUTIME"
,
"CSTIME"
,
"PRIORITY"
,
"NICE"
,
"ITREALVALUE"
,
"STARTTIME"
,
"VSIZE"
,
"RSS"
,
"RLIM"
,
"STARTCODE"
,
"ENDCODE"
,
"STARTSTACK"
,
"KSTKESP"
,
"KSTKEIP"
,
"SIGNAL"
,
"BLOCKED"
,
"SIGIGNORE"
,
"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"
,
"USER"
,
"TIME"
,
"*** report bug! ***"
};
static
int
Process_getuid
=
-
1
;
Process
*
Process_new
(
struct
ProcessList_
*
pl
)
{
Process
*
this
=
malloc
(
sizeof
(
Process
));
Object_setClass
(
this
,
PROCESS_CLASS
);
...
...
@@ -131,6 +132,7 @@ Process* Process_new(struct ProcessList_ *pl) {
this
->
utime
=
0
;
this
->
stime
=
0
;
this
->
comm
=
NULL
;
if
(
Process_getuid
==
-
1
)
Process_getuid
=
getuid
();
return
this
;
}
...
...
@@ -153,7 +155,7 @@ void Process_display(Object* cast, RichString* out) {
RichString_init
(
out
);
for
(
int
i
=
0
;
fields
[
i
];
i
++
)
Process_writeField
(
this
,
out
,
fields
[
i
]);
if
(
this
->
pl
->
shadowOtherUsers
&&
this
->
st_uid
!=
getuid
()
)
if
(
this
->
pl
->
shadowOtherUsers
&&
this
->
st_uid
!=
Process_
getuid
)
RichString_setAttr
(
out
,
CRT_colors
[
PROCESS_SHADOW
]);
if
(
this
->
tag
==
true
)
RichString_setAttr
(
out
,
CRT_colors
[
PROCESS_TAG
]);
...
...
@@ -315,9 +317,13 @@ void Process_writeField(Process* this, RichString* str, ProcessField field) {
case
M_SHARE
:
Process_printLargeNumber
(
this
,
str
,
this
->
m_share
*
PAGE_SIZE
);
return
;
case
ST_UID
:
snprintf
(
buffer
,
n
,
"%4d "
,
this
->
st_uid
);
break
;
case
USER
:
{
if
(
getuid
()
!=
this
->
st_uid
)
if
(
Process_
getuid
!=
this
->
st_uid
)
attr
=
CRT_colors
[
PROCESS_SHADOW
];
if
(
this
->
user
)
{
snprintf
(
buffer
,
n
,
"%-8s "
,
this
->
user
);
}
else
{
snprintf
(
buffer
,
n
,
"%-8d "
,
this
->
st_uid
);
}
if
(
buffer
[
8
]
!=
'\0'
)
{
buffer
[
8
]
=
' '
;
buffer
[
9
]
=
'\0'
;
...
...
Process.h
View file @
eb2803ce
...
...
@@ -34,7 +34,6 @@ in the source distribution for its full text.
#define PAGE_SIZE ( sysconf(_SC_PAGESIZE) / 1024 )
#define PROCESS_COMM_LEN 300
#define PROCESS_USER_LEN 10
typedef
enum
ProcessField_
{
...
...
@@ -107,7 +106,7 @@ typedef struct Process_ {
uid_t
st_uid
;
float
percent_cpu
;
float
percent_mem
;
char
user
[
PROCESS_USER_LEN
+
1
]
;
char
*
user
;
}
Process
;
...
...
ProcessList.c
View file @
eb2803ce
...
...
@@ -541,12 +541,7 @@ void ProcessList_processEntries(ProcessList* this, char* dirname, int parent, fl
goto
errorReadingProcess
;
if
(
!
existingProcess
)
{
char
*
username
=
UsersTable_getRef
(
this
->
usersTable
,
process
->
st_uid
);
if
(
username
)
{
strncpy
(
process
->
user
,
username
,
PROCESS_USER_LEN
);
}
else
{
snprintf
(
process
->
user
,
PROCESS_USER_LEN
,
"%d"
,
process
->
st_uid
);
}
process
->
user
=
UsersTable_getRef
(
this
->
usersTable
,
process
->
st_uid
);
snprintf
(
statusfilename
,
MAX_NAME
,
"%s/%s/cmdline"
,
dirname
,
name
);
status
=
ProcessList_fopen
(
this
,
statusfilename
,
"r"
);
...
...
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