summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--appl/cmd/broke.b84
-rw-r--r--appl/cmd/mkfile1
-rwxr-xr-xdis/broke4
-rw-r--r--dis/broke.disbin1135 -> 0 bytes
-rw-r--r--man/1/kill16
5 files changed, 16 insertions, 89 deletions
diff --git a/appl/cmd/broke.b b/appl/cmd/broke.b
deleted file mode 100644
index 41f2dd89..00000000
--- a/appl/cmd/broke.b
+++ /dev/null
@@ -1,84 +0,0 @@
-implement Broke;
-
-include "sys.m";
- sys: Sys;
-include "draw.m";
-
-Broke: module
-{
- init: fn(nil: ref Draw->Context, args: list of string);
-};
-
-init(nil: ref Draw->Context, nil: list of string)
-{
- sys = load Sys Sys->PATH;
- fd := sys->open("/prog", Sys->OREAD);
- if(fd == nil)
- err(sys->sprint("can't open /prog: %r"));
- killed := "";
- for(;;){
- (n, dir) := sys->dirread(fd);
- if(n <= 0){
- if(n < 0)
- err(sys->sprint("error reading /prog: %r"));
- break;
- }
- for(i := 0; i < n; i++)
- if(isbroken(dir[i].name) && kill(dir[i].name))
- killed += sys->sprint(" %s", dir[i].name);
- }
- if(killed != nil)
- sys->print("%s\n", killed);
-}
-
-isbroken(pid: string): int
-{
- statf := "/prog/" + pid + "/status";
- fd := sys->open(statf, Sys->OREAD);
- if (fd == nil)
- return 0;
- buf := array[256] of byte;
- n := sys->read(fd, buf, len buf);
- if (n < 0) { # process died or is exiting
- # sys->fprint(stderr(), "broke: can't read %s: %r\n", statf);
- return 0;
- }
- (nf, l) := sys->tokenize(string buf[0:n], " ");
- return nf >= 5 && hd tl tl tl tl l == "broken";
-}
-
-kill(pid: string): int
-{
- ctl := "/prog/" + pid + "/ctl";
- fd := sys->open(ctl, sys->OWRITE);
- if(fd == nil || sys->fprint(fd, "kill") < 0){
- sys->fprint(stderr(), "broke: can't kill %s: %r\n", pid); # but press on
- return 0;
- }
- return 1;
-}
-
-err(s: string)
-{
- sys->fprint(sys->fildes(2), "broke: %s\n", s);
- raise "fail:error";
-}
-
-stderr(): ref Sys->FD
-{
- return sys->fildes(2);
-}
-
-user(): string
-{
- fd := sys->open("/dev/user", sys->OREAD);
- if(fd == nil)
- return "inferno";
-
- buf := array[64] of byte;
- n := sys->read(fd, buf, len buf);
- if(n <= 0)
- return "inferno";
-
- return string buf[0:n];
-}
diff --git a/appl/cmd/mkfile b/appl/cmd/mkfile
index 8106e401..892f65cb 100644
--- a/appl/cmd/mkfile
+++ b/appl/cmd/mkfile
@@ -34,7 +34,6 @@ TARG=\
basename.dis\
bind.dis\
# bit2gif.dis\
- broke.dis\
bytes.dis\
cal.dis\
calc.dis\
diff --git a/dis/broke b/dis/broke
new file mode 100755
index 00000000..b65a6ed8
--- /dev/null
+++ b/dis/broke
@@ -0,0 +1,4 @@
+#!/dis/sh.dis
+load std
+if {~ $#* 1} {U=$1} {U=`{cat /dev/user}}
+ps | sed -n -e '/^[ ]*[0-9]+[ ]+[0-9]+[ ]+'$U'.*broken/s%^[ ]*([0-9]+)[ ]+.*([^ ]+)$%echo kill>/prog/\1/ctl # &%p'
diff --git a/dis/broke.dis b/dis/broke.dis
deleted file mode 100644
index e96c4cdf..00000000
--- a/dis/broke.dis
+++ /dev/null
Binary files differ
diff --git a/man/1/kill b/man/1/kill
index 27b39a6a..151ec170 100644
--- a/man/1/kill
+++ b/man/1/kill
@@ -14,6 +14,9 @@ kill, broke \- terminate process(es)
]
.PP
.B broke
+[
+.I user
+]
.SH DESCRIPTION
.I Kill
terminates each process (for a numeric
@@ -46,9 +49,14 @@ file, and the process ID of each such process is printed on standard output.
A process that incurs an exception (eg, array bounds check)
is normally suspended in the `broken' state to allow debugging.
.I Broke
-kills all such processes owned by the current user, releasing any resources
-they hold back to the system;
-it prints their process IDs.
+finds all such processes owned by
+.I user
+(default: the current user), and
+prints
+.I sh (1)
+commands to them.
+The commands can be piped to the shell or selectively run,
+releasing back to the system any resources owned by those processes.
.SH FILES
.TF "/prog/pid/status "
.TP
@@ -58,7 +66,7 @@ it prints their process IDs.
.SH SOURCE
.B /appl/cmd/kill.b
.br
-.B /appl/cmd/broke.b
+.B /dis/broke
.SH "SEE ALSO"
.IR ps (1),
.IR prog (3)