fixed
This commit is contained in:
parent
1b9dc6d7dc
commit
0737916f1a
11 changed files with 71 additions and 35 deletions
|
@ -121,7 +121,7 @@ int main(int argc, char **argv) {
|
|||
ret = 1;
|
||||
|
||||
for (int i = 0; i < argc; i++) {
|
||||
if (!strcmp(proc.prog, argv[i]))
|
||||
if (!strcmp(proc.cmdline, argv[i]))
|
||||
if (my_kill(pid, signal))
|
||||
ret = 1;
|
||||
}
|
||||
|
|
50
src/ps.c
50
src/ps.c
|
@ -1,3 +1,4 @@
|
|||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
@ -6,9 +7,34 @@
|
|||
#include <errno.h>
|
||||
#include <pwd.h>
|
||||
#include <time.h>
|
||||
#include <limits.h>
|
||||
#include "proc_parser.h"
|
||||
#include "human.h"
|
||||
|
||||
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))
|
||||
|
@ -25,19 +51,31 @@ static int pscan(const pid_t pid) {
|
|||
|
||||
/* Print */
|
||||
char virt[MU_HUMAN_BUF_SIZE + 1];
|
||||
strcpy(virt, mu_humansize((off_t)proc.vsize, 1024));
|
||||
strcpy(virt, mu_humansize(proc.vsize, 1024));
|
||||
|
||||
char rss[MU_HUMAN_BUF_SIZE + 1];
|
||||
strcpy(rss, mu_humansize((off_t)proc.vmrss * 1024, 1024));
|
||||
strcpy(rss, mu_humansize(proc.vmrss * 1024, 1024));
|
||||
|
||||
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, proc.prog);
|
||||
char *prog = (c_flag) ? get_cmdline(pid) : proc.cmdline;
|
||||
if (prog == NULL)
|
||||
prog = proc.cmdline;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
while (getopt(argc, argv, "") != -1) {
|
||||
puts("ps [a] [PID]\n\t-a Print all processes\n");
|
||||
return 0;
|
||||
int opt;
|
||||
while ((opt = getopt(argc, argv, "c")) != -1) {
|
||||
switch (opt) {
|
||||
case 'c':
|
||||
c_flag = 1;
|
||||
break;
|
||||
|
||||
default:
|
||||
puts("ps [c] [PID]\n\t-c Print cmdline instead of program name");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
argv += optind;
|
||||
|
|
|
@ -42,8 +42,7 @@ static char *file_path;
|
|||
|
||||
enum {
|
||||
FAILED_SAVE = 1,
|
||||
SUCCESS_SAVE,
|
||||
MARK
|
||||
SUCCESS_SAVE
|
||||
};
|
||||
static char status_type;
|
||||
static char modified_flag;
|
||||
|
@ -419,9 +418,6 @@ static void statusBar(const char *path) {
|
|||
else if (status_type == SUCCESS_SAVE)
|
||||
ret = snprintf(info, sizeof(info), "File %s success saved", path);
|
||||
|
||||
else if (status_type == MARK)
|
||||
ret = snprintf(info, sizeof(info), "Mark set at %ux %uy", curx, cury);
|
||||
|
||||
status_type = 0;
|
||||
bufAppend(info, ret);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue