fixed ps
This commit is contained in:
parent
c705f3b30b
commit
c6e315c24c
3 changed files with 43 additions and 30 deletions
28
src/ps.c
28
src/ps.c
|
@ -13,28 +13,6 @@
|
|||
|
||||
static char c_flag;
|
||||
|
||||
static char *get_cmdline(const pid_t pid) {
|
||||
static char path[PATH_MAX + 1];
|
||||
snprintf(path, sizeof(path), "/proc/%d/cmdline", pid);
|
||||
|
||||
int fd = open(path, O_RDONLY);
|
||||
if (fd < 0)
|
||||
return NULL;
|
||||
|
||||
ssize_t size = read(fd, path, sizeof(path));
|
||||
close(fd);
|
||||
|
||||
if (size == 0)
|
||||
return NULL;
|
||||
|
||||
for (ssize_t i = 0; i < size; i++) {
|
||||
if (path[i] == '\0' && i != size - 1)
|
||||
path[i] = ' ';
|
||||
}
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
static int pscan(const pid_t pid) {
|
||||
struct mu_proc proc;
|
||||
if (mu_proc_parser("ps", pid, &proc))
|
||||
|
@ -56,9 +34,9 @@ static int pscan(const pid_t pid) {
|
|||
char rss[MU_HUMAN_BUF_SIZE + 1];
|
||||
strcpy(rss, mu_humansize(proc.vmrss * 1024, 1024));
|
||||
|
||||
char *prog = (c_flag) ? get_cmdline(pid) : proc.cmdline;
|
||||
if (prog == NULL)
|
||||
prog = proc.cmdline;
|
||||
char *prog = (c_flag) ? proc.cmdline : proc.cmd;
|
||||
if (prog[0] == '\0')
|
||||
return 0;
|
||||
|
||||
printf("%6d %8s %4ld %4ld %8s %8s %2c %02um:%02us %2s\n", proc.pid, name, proc.priority, proc.nice, virt, rss, proc.state, rtime / 60, rtime % 60, prog);
|
||||
return 0;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue