diff --git a/src/cgutil.c b/src/cgutil.c index 3ed591b8..cc8be99b 100644 --- a/src/cgutil.c +++ b/src/cgutil.c @@ -446,6 +446,7 @@ int show_cgtop(char *arg) { struct sysinfo si = { 0 }; char path[512]; + int laps = 0; if (!arg) arg = FINIT_CGPATH; @@ -465,6 +466,9 @@ int show_cgtop(char *arg) if (heading) print_header(" VmSIZE RSS VmLIB %%MEM %%CPU GROUP"); cgroup_tree(arg, NULL, 1); + + if (ionce && laps++) + break; sleep(1); } diff --git a/src/initctl.c b/src/initctl.c index e5666c3f..0013081a 100644 --- a/src/initctl.c +++ b/src/initctl.c @@ -50,6 +50,7 @@ struct cmd { int icreate = 0; int iforce = 0; +int ionce = 0; int heading = 1; int verbose = 0; int plain = 0; @@ -714,6 +715,7 @@ static int usage(int rc) " -b, --batch Batch mode, no screen size probing\n" " -c, --create Create missing paths (and files) as needed\n" " -f, --force Ignore missing files and arguments, never prompt\n" + " -1, --once Only one lap in commands like 'top'\n" " -p, --plain Use plain table headings, no ctrl chars\n" " -t, --no-heading Skip table headings\n" " -v, --verbose Verbose output\n" @@ -842,6 +844,7 @@ int main(int argc, char *argv[]) { "create", 0, NULL, 'c' }, { "force", 0, NULL, 'f' }, { "help", 0, NULL, 'h' }, + { "once", 0, NULL, '1' }, { "plain", 0, NULL, 'p' }, { "no-heading", 0, NULL, 't' }, { "verbose", 0, NULL, 'v' }, @@ -898,8 +901,12 @@ int main(int argc, char *argv[]) if (transform(progname(argv[0]))) return reboot_main(argc, argv); - while ((c = getopt_long(argc, argv, "bcfh?ptv", long_options, NULL)) != EOF) { + while ((c = getopt_long(argc, argv, "1bcfh?ptv", long_options, NULL)) != EOF) { switch(c) { + case '1': + ionce = 1; + break; + case 'b': interactive = 0; break; diff --git a/src/initctl.h b/src/initctl.h index a0dd50ca..256b72ec 100644 --- a/src/initctl.h +++ b/src/initctl.h @@ -29,6 +29,7 @@ extern int icreate; /* initctl -c */ extern int iforce; /* initctl -f */ +extern int ionce; /* initctl -1 */ extern int heading; /* initctl -t */ extern int verbose; /* initctl -v */ extern int plain; /* initctl -p */