chmod +x all sh scripts so they can run from the git checkout
[catalyst.git] / targets / support / kill-chroot-pids.sh
1 #!/bin/bash
2 # Script to kill processes found running in the chroot.
3
4 if [ "${clst_chroot_path}" == "/" ]
5 then
6         echo "Aborting .... clst_chroot_path is set to /"
7         echo "This is very dangerous"
8         exit 1
9 fi
10
11 if [ "${clst_chroot_path}" == "" ]
12 then
13         echo "Aborting .... clst_chroot_path is NOT set"
14         echo "This is very dangerous"
15         exit 1
16 fi
17
18 j=0
19 declare -a pids
20 # Get files and dirs in /proc
21 for i in `ls /proc`
22 do
23         # Test for directories
24         if [ -d /proc/$i ]
25         then
26         # Search for exe containing string inside ${clst_chroot_path}
27         ls -la --color=never /proc/$i 2>&1 |grep exe|grep ${clst_chroot_path} > /dev/null
28
29         # If found
30         if [ $? == 0 ]
31         then
32                 # Assign the pid into the pids array
33                 pids[$j]=$i
34                 j=$(($j+1))
35         fi
36         fi
37 done
38
39 if [ ${j} -gt 0 ]
40 then
41         echo
42         echo "Killing process(es)"
43         echo "pid: process name"
44         for pid in ${pids[@]}
45         do
46                 P_NAME=$(ls -la --color=never /proc/${pid} 2>&1 |grep exe|grep ${clst_chroot_path}|awk '{print $11}')
47                 echo ${pid}: ${P_NAME}
48         done
49         echo
50         echo "Press Ctrl-C within 10 seconds to abort"
51
52         sleep 10
53
54         for pid in ${pids[@]}
55         do
56                 kill -9 ${pid}
57         done
58
59         # Small sleep here to give the process(es) a chance to die before running unbind again.
60         sleep 5
61
62 fi