File: fiu-ls

package info (click to toggle)
libfiu 0.90-3
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 376 kB
  • sloc: ansic: 1,272; makefile: 412; python: 397; sh: 263
file content (48 lines) | stat: -rwxr-xr-x 1,087 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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