View Single Post
  #1   (View Single Post)  
Old 25th March 2009
TerryP's Avatar
TerryP TerryP is offline
Arp Constable
 
Join Date: May 2008
Location: USofA
Posts: 1,547
Default a novel idea: a sh with a `fork" built-in?

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 tpsh 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.
__________________
My Journal

Thou shalt check the array bounds of all strings (indeed, all arrays), for surely where thou typest ``foo'' someone someday shall type ``supercalifragilisticexpialidocious''.

Last edited by TerryP; 25th March 2009 at 03:44 AM.
Reply With Quote