On 06/04/2014 09:19 AM, Adrian Popa wrote:
> N-am screen. O să caut unul compilat static, dar problema e că mă aștept să
> fie >64K și nu o să am unde să-l flash-uiesc. Mă mai uit și la varianta
> unui wrapper simplu în C care să facă fork scriptului sh...
>
Ai incercat o cautare pe google dupa busybox background process?
Am gasit ceva interesant in primul link:
http://stackoverflow.com/questions/285015/linux-prevent-a-background-process-from-being-stopped-after-closing-ssh-client
#!/bin/bash
IFS=
run_in_coproc () {
echo "coproc[$1] -> main"
read -r; echo $REPLY
}
# dynamic-coprocess-generator. nice.
_coproc () {
local i o e n=${1//[^A-Za-z0-9_]}; shift
exec {i}<> <(:) {o}<> >(:) {e}<> >(:)
. /dev/stdin <<COPROC "${@}"
(("\$@")&) <&$i >&$o 2>&$e
$n=( $o $i $e )
COPROC
}
# pi-rads-of-awesome?
for x in {0..5}; do
_coproc COPROC$x run_in_coproc $x
declare -p COPROC$x
done
for x in COPROC{0..5}; do
. /dev/stdin <<RUN
read -r -u \${$x[0]}; echo \$REPLY
echo "$x <- main" >&\${$x[1]}
read -r -u \${$x[0]}; echo \$REPLY
RUN
done
... save as coproc.sh ...
# ./coproc.sh
declare -a COPROC0='([0]="21" [1]="16" [2]="23")'
declare -a COPROC1='([0]="24" [1]="19" [2]="26")'
declare -a COPROC2='([0]="27" [1]="22" [2]="29")'
declare -a COPROC3='([0]="30" [1]="25" [2]="32")'
declare -a COPROC4='([0]="33" [1]="28" [2]="35")'
declare -a COPROC5='([0]="36" [1]="31" [2]="38")'
coproc[0] -> main
COPROC0 <- main
coproc[1] -> main
COPROC1 <- main
coproc[2] -> main
COPROC2 <- main
coproc[3] -> main
COPROC3 <- main
coproc[4] -> main
COPROC4 <- main
coproc[5] -> main
COPROC5 <- main
... and there you go, spawn whatever. the <(:) opens an anonymous pipe
via process substitution, which dies, but the pipe sticks around because
you have a handle to it. i usually do a sleep 1 instead of : because its
slightly racy, and i'd get a "file busy" error -- never happens if a
real command is ran (eg, command true)
... "heredoc sourcing":
. /dev/stdin <<EOF
[...]
EOF
... works on every single shell i've ever tried, including busybox/etc
(initramfs). i've never seen it done before -- i independently
discovered it while prodding, who knew source could accept args?? -- but
it often serves as a much more manageable form of eval, if there is such
a thing ...
--
Tudor Gheorghe
_______________________________________________
RLUG mailing list
[email protected]
http://lists.lug.ro/mailman/listinfo/rlug