whilst pushing a broom today, the following idea hit me:
Code:
# a super simple but conceptual example
# a variable to communicate status between child/parent
fork ALIVE
if [ $? -eq -1 ]; then
echo "$0: Unable to fork for ..., stopping $0"
exit 255
elsif [ $? -ge 0 ]; then
echo "doing processing: ... whatever"
# when the child exits, the variable becomes false (and exits the loop)
while [ $ALIVE ]; do
echo '.'
done
echo 'done processing'
else
do lengthy processing in child
exit 1
fi
like so much other software out there, my t
psh does synchronous execution of external commands by way of fork()'ing, followed by a wait() in the parent and an exec() in the child. ('&', job control, '[', and control flow are not implemented yet)
Then I thought, well hell, if the shell can fork stuff all day and we can use the & to execute programs asynchronously and move on - why shouldn't shell script be able to access the fork system call directly through a shell built in command? Implementing it shouldn't be much harder then the &, [, and control/flow stuff that needs doing anyway, and to me it sounds like an interesting feature/extension.
I was wondering if anyone else had an opinion on this idea.