Skip to content
This repository has been archived by the owner on Dec 28, 2018. It is now read-only.

Commit

Permalink
new: closes #1 and speedup kill & umount
Browse files Browse the repository at this point in the history
the processes to be excluded from the global kill can be
chosen by the new variables in fishing/FIsH.porting:
EXCLUDEPROCS / EXCLUDEPIDS

This commit makes heavy advantage of the new F_PS
function introduced in a previous commit and enhances the
killing in any possible way to speed up as much as we can.

Previous runs took about 10-15 sec to kill processes which is
about 3-5 sec now (on my device at least).
Instead of killing pid by pid in a slow for loop we create a list
of pids, exclude those we do not want to kill (see above vars)
and then using one single kill cmd to blow them all.

Change-Id: I31cee335452816e39e4aea02cea29f2ccff34aa8
  • Loading branch information
steadfasterX committed Jun 14, 2017
1 parent a590301 commit f57b23f
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 17 deletions.
52 changes: 36 additions & 16 deletions fishing/FIsH
Original file line number Diff line number Diff line change
Expand Up @@ -243,24 +243,44 @@ if [ -f ${BTMGRPATH}/${RAMDISK} ];then
#done
EXECL $MOUNT -oremount,rw /system

ECHOL " # Generating pid exclusion list based on EXCLUDEPROCS..."
# create list of excluded PIDs based on given names
unset FILTERPIDS
NAMEMAP=$(F_PS |$EGREP "$EXCLUDEPROCS" |cut -d ":" -f1 | $TR "\n" "|" |sed 's/||//g;s/|$//g'|$SORT -u)
ECHOL "based on >$EXCLUDEPROCS< these pid(s) were found: <$NAMEMAP>"
[ ! -z "$NAMEMAP" ]&& FILTERPIDS="$NAMEMAP"

#DEBUG:
#ECHOL "These pids of PROCESS NAMES get excluded from being killed <$FILTERPIDS> as defined in EXCLUDEPROCS ($EXCLUDEPROCS)"

# if filter pids were specified add them as well
[ ! -z "$EXCLUDEPIDS" ] && [ ! -z "$FILTERPIDS" ] && FILTERPIDS="$FILTERPIDS|$EXCLUDEPIDS|$PID"
[ ! -z "$EXCLUDEPIDS" ] && [ -z "$FILTERPIDS" ] && FILTERPIDS="$EXCLUDEPIDS|$PID"

#DEBUG:
#ECHOL "These PIDs get excluded from being killed as defined in EXCLUDEPIDS: <$EXCLUDEPIDS>\nIn sum all these PIDs get excluded from being killed: <$FILTERPIDS> ($PID is FIsH itself ;))"

# umount all normal mounts (no /system yet!)
ECHOL "### killing all processes accessing defined mountpoints (if any can be found by fuser and not excluded)"
MOUNTS=$(for mountp in $MOUNTS;do [ -e "$mountp" ] && echo $mountp ;done)
# convert newlines in MOUNTS variable into spaces
SPACEMNT=$($ECHO $MOUNTS)
TOKILL=$($FUSER -m $SPACEMNT | $TR ' ' '\n' | $SORT -u | $EGREP -v "$FILTERPIDS" | $TR '\n' ' ')
PSGREP=$($ECHO "$TOKILL" | $SED -e 's/\([0-9]*\)/^\1:|/g;s/ //g;s/||//g;s/\^:|//g;s/|$//g')
ECHOL "$FUSER -m $SPACEMNT | $TR ' ' '\\n' | $EGREP -v '$FILTERPIDS' | $TR '\\n' ' '"

if [ ! -z "$TOKILL" ];then
echo "Trying to kill ($PSGREP):" >> $LOGFILE
F_PS | $EGREP "$PSGREP" >> $LOGFILE
$ECHO "cmd: $KILL -9 $TOKILL" >> $LOGFILE
$KILL -9 $TOKILL >> $LOGFILE 2>&1
#ECHOL "KILLING $PSGREP IS DISABLED"
else
ECHOL "Empty pid skipped..!"
fi
ECHOL "### unmounting all defined (and also available) partitions"
for i in $MOUNTS;do
if [ -e "$i" ];then
ECHOL "### killing all processes accessing $i (if any can be found by fuser)"
for pid in $($FUSER -m $i);do
if [ $pid -eq $PID ]||[ $pid -eq 1 ];then
ECHOL "skipped to kill excluded pid $pid"
else
if [ ! -z $pid ];then
echo "Trying to kill"
$PS -T -o pid,comm,args | $GREP $pid >> $LOGFILE
#$KILL -9 $pid >> $LOGFILE 2>&1
ECHOL "KILLING IS DISABLED"
else
ECHOL "Empty pid skipped..!"
fi
fi
done
if [ -e $i ];then
EXECL ${UMOUNT} $i || EXECL ${UMOUNT} -f $i || EXECL ${UMOUNT} -l $i
else
ECHOL "Skipped requested unmount because it does not exist ($i)"
Expand Down
19 changes: 18 additions & 1 deletion fishing/FIsH.porting
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,23 @@ SPECMOUNTS="/dev/usb-ffs/adb \
/sys"


# once FIsH starts to unmount filesystems it will first try to kill all processes
# currently accessing that mountpoint. You can specify here either process name(s) (FIsH
# checks the arg so e.g. when /bin/sh starts a script u can filter on that script name)
# or you can specify fix PID(s) <- that one makes no sense in most cases and e.g. PID 1
# (init) is the main reason when to use it.
# ATTENTION:
# - multiple process names have to be separated by a PIPE: |
# - process names are CASE SENSITIVE
# (means: "FISH" will match "FIsH" but also "FISHing" or "myfish")
# - special chars are not tested!
EXCLUDEPROCS="kworker|irq|interrupt|watchdog|busybox|FIsH"
# ensure 1 is always set here! If u wanna add more feel free but keep in mind that
# everything else then init (pid 1) is dynamic and change on each boot
# ATTENTION: multiple PIDs have to be separated by a PIPE: |
EXCLUDEPIDS="1"



### PORTING SECTION END ###
##################################################################################
##################################################################################

0 comments on commit f57b23f

Please sign in to comment.