Go Back   DaemonForums > Miscellaneous > Programming

Programming C, bash, Python, Perl, PHP, Java, you name it.

Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #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,546
Default a novel idea: a sh with a `fork" built-in?

whilst pushing a broom today, the following idea hit me:

# 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 '.'
    echo 'done processing'
    do lengthy processing in child
    exit 1

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

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Keyboard with built in mouse trackball blodan FreeBSD General 2 21st June 2008 07:44 PM

All times are GMT. The time now is 09:06 PM.

Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
Content copyright © 2007-2010, the authors
Daemon image copyright ©1988, Marshall Kirk McKusick