aboutsummaryrefslogtreecommitdiffstats
path: root/bash_include
diff options
context:
space:
mode:
authorLAN-TW <lantw44@gmail.com>2012-02-14 22:43:59 +0800
committerLAN-TW <lantw44@gmail.com>2012-02-14 22:43:59 +0800
commit1e0f0f8921c43a081b0b063ee10f1e5159b50148 (patch)
treeced945412631985d8116b3ac9a8b5b6884ff4924 /bash_include
parent36683da367a62545d9c7c65ef96733640cbca7c1 (diff)
downloadconfigfile-1e0f0f8921c43a081b0b063ee10f1e5159b50148.tar
configfile-1e0f0f8921c43a081b0b063ee10f1e5159b50148.tar.gz
configfile-1e0f0f8921c43a081b0b063ee10f1e5159b50148.tar.bz2
configfile-1e0f0f8921c43a081b0b063ee10f1e5159b50148.tar.lz
configfile-1e0f0f8921c43a081b0b063ee10f1e5159b50148.tar.xz
configfile-1e0f0f8921c43a081b0b063ee10f1e5159b50148.tar.zst
configfile-1e0f0f8921c43a081b0b063ee10f1e5159b50148.zip
bash_include: 將背景 process 的 PID 寫入檔案bash_include-20120214
Diffstat (limited to 'bash_include')
-rw-r--r--bash_include39
1 files changed, 30 insertions, 9 deletions
diff --git a/bash_include b/bash_include
index 39b7de6..ebf0c15 100644
--- a/bash_include
+++ b/bash_include
@@ -154,6 +154,7 @@ function bgrun ()
{
[ "$#" = "0" ] && return 1
[ '!' -d "$bgrunfiledir" ] && mkdir -p "$bgrunfiledir"
+# [ '!' -d "$bgrunfiledir/pid" ] && mkdir -p "$bgrunfiledir/pid"
local current_time=`date "+%Y%m%d-%H%M%S"`
local cmdname=`echo "$1" | sed -e 's/-/_/g' -e 's/\\//_/g' -e 's/ /_/g'`
if [ "`echo "$cmdname" | cut -c 1`" == "_" ]
@@ -162,22 +163,37 @@ function bgrun ()
fi
local filename="$bgrunfiledir/$current_time-$cmdname"
echo "Writing to $filename"
- echo "$@" > $filename
- "$@" &>> "$filename" &
+ {
+ echo -n "$BASHPID " > "$filename"
+ echo "$@" >> "$filename"
+ exec "$@" &>> "$filename"
+ } &
}
function bglist ()
{
local viewtime=0
[ "$1" = "--full" ] && viewtime=1
+ if [ "$viewtime" = "1" ]
+ then
+ echo " INDEX TIME PID COMMAND"
+ else
+ echo " INDEX PID COMMAND"
+ fi
{
for i in `find "$bgrunfiledir" -maxdepth 1 -mindepth 1 | sort`
do
- [ "$viewtime" == "1" ] && echo "$i"
- head -n 1 "$i"
+ [ "$viewtime" = "1" ] && echo "$i"
+ head -n 1 "$i" | {
+ local procpid
+ local cmdline
+ read -d ' ' procpid
+ read cmdline
+ printf "(%5d) %s\n" "$procpid" "$cmdline"
+ }
done
} | {
- if [ "$viewtime" == "1" ]
+ if [ "$viewtime" = "1" ]
then
local readstat=0
local -i i=1
@@ -230,14 +246,19 @@ function bgview ()
fi
echo "Your choice is $yourchoice."
local realfilename=`find "$bgrunfiledir" -maxdepth 1 -mindepth 1 | sort | sed -n ${yourchoice}p`
- echo "Command Line: `head -n 1 "$realfilename"`"
+ head -n 1 "$realfilename" | {
+ read -d ' ' procpid
+ read cmdline
+ echo "PID: $procpid"
+ echo "Command Line: $cmdline"
+ }
read -e -p "View '$realfilename' ? " confirm
if [ "$confirm" = "n" ] || [ "$confirm" = "N" ]
then
return 1
fi
{
- printf "Command Line: "
+ printf "===> Process Information: "
cat "$realfilename"
} | $PAGER
}
@@ -380,7 +401,7 @@ function trash_rm ()
i=$i+1
done
trash_dirname=`find "$trashdir" -mindepth 1 -maxdepth 1 | sort | sed -n ${arglist[*]} `
- echo 'Type rm -rf $trash_dirname to remove.'
+ echo 'Type rm -rf $trash_dirname to remove them.'
unset arglist
unset prefixlist
}
@@ -581,7 +602,7 @@ function path_editor_core ()
read -e -p "[A]ppend/(D)elete/(E)dit/(M)ove/(R)eset/(Q)uit ? " command
case "$command" in
''|A|a)
- read -e -p "Type new entry: " patharr[$i]
+ read -e -p "Type a new entry: " patharr[$i]
update_path
;;
D|d)