From 5a8a6d70c0bcf145b24443add653b2302a3a9571 Mon Sep 17 00:00:00 2001 From: Victor Rodriguez Date: Thu, 1 Dec 2016 22:58:50 +0000 Subject: [PATCH] Fix printing format in a pretty way This patch improve the way that psstop prints the results: Process Name PID : Size in KB [...] systemd-udevd 23356 : 0 Kb systemd 24050 : 2183 Kb (sd-pam) 24051 : 0 Kb tmux: server 31523 : 1087 Kb bash 31524 : 4 Kb bash 31525 : 4 Kb vim 31684 : 4 Kb Total is 19871Kb (181 processes) Signed-off-by: Victor Rodriguez --- src/main.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main.c b/src/main.c index 4833ae8..6fd0950 100644 --- a/src/main.c +++ b/src/main.c @@ -84,7 +84,7 @@ static void do_one_process(int pid) fclose(file); } - printf("%" PRIu64 " Kb: %s (%i) \n", process.PSS_kb, process.name, pid); + printf("%-20s %-5i : %-5" PRIu64 " Kb\n",process.name, pid , process.PSS_kb); total_PSS += process.PSS_kb; total_proc++; free(process.name); @@ -100,6 +100,8 @@ int main(int argc, char **argv) } dir = opendir("/proc"); + + printf("\n%-20s %-5s : %-5s \n\n","Process Name", "PID", "Size in KB"); while (dir) { int pid; entry = readdir(dir); @@ -111,7 +113,7 @@ int main(int argc, char **argv) do_one_process(pid); } - printf("Total is %" PRIu64 "Kb (%i processes)\n", total_PSS, total_proc); + printf("\nTotal is %" PRIu64 "Kb (%i processes)\n", total_PSS, total_proc); closedir(dir); free(searchkey); return EXIT_SUCCESS;