source: branches/profile/SH/arb_clean

Last change on this file was 11815, checked in by westram, 10 years ago
  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 1.6 KB
Line 
1#!/bin/bash
2
3remove() {
4    local PIDFILE=$1
5    rm -f $PIDFILE
6}
7killandremove() {
8    local PIDFILE=$1
9    kill -9 `cat $PIDFILE` >/dev/null 2>&1
10    remove $PIDFILE
11}
12cat_newline() {
13    local PIDFILE=$1
14    cat $PIDFILE
15    echo ""
16}
17
18witheach() {
19    local CMDPREFIX=$*
20    local PIDFILE
21    while read PIDFILE; do
22        $CMDPREFIX $PIDFILE
23    done
24}
25
26allpidfiles() {
27    ls ~/.arb_tmp/tmp/arb_pids_${USER}_* 2>&1 | grep -v 'No such file'
28}
29
30# ----------------------------------------
31
32session() {
33    local PIDFILE=~/.arb_tmp/tmp/arb_pids_${USER}_${ARB_PID}
34    if [ -f $PIDFILE ]; then
35        echo $PIDFILE | witheach killandremove
36    else
37        echo "No processes listed for ARB_PID=$ARB_PID"
38    fi
39}
40
41old() {
42    allpidfiles | witheach remove
43}
44targets() {
45    allpidfiles | witheach cat_newline
46}
47killall() {
48    allpidfiles | witheach killandremove
49}
50
51# ----------------------------------------
52
53ACTION=$1
54if [ -z "$ACTION" ]; then
55    echo "Usage: arb_clean [action]"
56    echo "Known actions are:"
57    echo "    session           kill all processes running with current ARB_PID"
58    echo "    old               delete old pid-files from /tmp (dont do this while arb is running)"
59    echo "    targets           show process ids of processes, that will be killed by action 'killall'"
60    echo "    killall           kill all (current or former) arb processes"
61    echo "                      CAUTION: may act completely wrong and kill various running non-ARB-processes!"
62else
63    if [ "$ACTION" == "session" -o "$ACTION" == "old" -o "$ACTION" == "targets" -o "$ACTION" == "killall" ]; then
64        $ACTION
65    fi
66fi
Note: See TracBrowser for help on using the repository browser.