git » libfiu » commit ae3e192

fiu-ls: list processes that can be controlled

author Tommi Rantala
2009-07-08 06:05:22 UTC
committer Alberto Bertogli
2009-07-08 14:21:32 UTC
parent 0d4f4bd9c3f7c83cbb78f70251c118325f1b65af

fiu-ls: list processes that can be controlled

fiu-ls is a tool for listing processes that can be controlled fiu-ctrl.

Signed-off-by: Tommi Rantala <tt.rantala@gmail.com>

utils/Makefile +2 -0
utils/fiu-ls +48 -0
utils/fiu-ls.1 +31 -0

diff --git a/utils/Makefile b/utils/Makefile
index 573efba..3943711 100644
--- a/utils/Makefile
+++ b/utils/Makefile
@@ -11,8 +11,10 @@ default:
 install:
 	$(INSTALL) -d $(PREFIX)/bin
 	$(INSTALL) -m 0755 fiu-ctrl $(PREFIX)/bin
+	$(INSTALL) -m 0755 fiu-ls $(PREFIX)/bin
 	$(INSTALL) -d $(PREFIX)/man/man1
 	$(INSTALL) -m 0644 fiu-ctrl.1 $(PREFIX)/man/man1/
+	$(INSTALL) -m 0644 fiu-ls.1 $(PREFIX)/man/man1/
 
 clean:
 
diff --git a/utils/fiu-ls b/utils/fiu-ls
new file mode 100644
index 0000000..4ee4dc1
--- /dev/null
+++ b/utils/fiu-ls
@@ -0,0 +1,48 @@
+#!/usr/bin/env bash
+# Lists processes that can be controlled with fiu-ctrl.
+
+# default remote control over named pipes prefix; we use the same one as
+# fiu-run so it's easier to use
+FIFO_PREFIX="${TMPDIR:-/tmp}/fiu-ctrl"
+
+declare -a PIDS
+
+HELP_MSG="
+Usage: fiu-ls [options]
+
+The following options are supported:
+
+  -f ctrlpath	Set the default prefix for remote control over named pipes.
+		(defaults to \"$FIFO_PREFIX\", which is usually correct if
+		the program was run using fiu-run(1)).
+"
+
+while getopts "f:h" opt; do
+	case $opt in
+	f)
+		FIFO_PREFIX="$OPTARG"
+		;;
+	h|*)
+		echo "$HELP_MSG"
+		exit 1
+		;;
+	esac;
+done
+
+for P in `ls -1 $FIFO_PREFIX-*.in 2>/dev/null` ; do
+	if [ -n "$P" ] ; then
+		OUT="`echo $P | cut -d. -f1`.out"
+		if [ -p "$P" -a -w "$P" -a -p "$OUT" -a -r "$OUT" ] ; then
+			PID="`echo $P | cut -d- -f3 | cut -d. -f1`"
+			if [ -n "$PID" ] && \
+			   kill -0 "$PID" >/dev/null 2>/dev/null ; then
+				PIDS[${#PIDS[*]}]="$PID"
+			fi
+		fi
+	fi
+done
+
+for P in "${PIDS[@]}"; do
+	CMDLINE="`tr '\0' ' ' < /proc/$P/cmdline 2>/dev/null`"
+	printf "%5d: %s\n" "$P" "$CMDLINE"
+done
diff --git a/utils/fiu-ls.1 b/utils/fiu-ls.1
new file mode 100644
index 0000000..c56b569
--- /dev/null
+++ b/utils/fiu-ls.1
@@ -0,0 +1,31 @@
+.TH fiu-ls 1 "7/Jul/2009"
+.SH NAME
+fiu-ls - list processes available for libfiu remote control
+.SH SYNOPSIS
+fiu-ls [options]
+
+.SH DESCRIPTION
+fiu-ls lists process that are available to be controlled using the libfiu
+\fBfiu-ctrl\fR(1) utility. Such processes have the remote control pipes
+available.
+
+For additional documentation, go to the project's website at
+.IR http://blitiri.com.ar/p/libfiu .
+
+.SH OPTIONS
+.TP
+.B "-f ctrlpath"
+Set the default prefix for remote control over named pipes. Defaults to
+"$TMPDIR/fiu-ctrl", or "/tmp/fiu-ctrl" if "$TMPDIR" is not set, which is the
+usually correct for programs launched using \fBfiu-run\fR(1).
+
+.SH SEE ALSO
+.BR libfiu (3),
+.BR fiu-ctrl (1),
+.BR fiu-run (1).
+
+.SH BUGS
+If you want to report bugs, or have any questions or comments, just let me
+know at albertito@blitiri.com.ar. For more information about libfiu, you can
+go to http://blitiri.com.ar/p/libfiu.
+