[plt-scheme] Teach Yourself Scheme

From: Eli Barzilay (eli at barzilay.org)
Date: Thu Jan 21 13:00:44 EST 2010

On Jan 21, John Clements wrote:
> I figured I needed mred for scheme/sandbox stuff, but I just tried
> it with mzscheme, and it works fine. Thanks!

The process would also be much lighter.

> > (And BTW, all those disown/nohup/etc things shouldn't be needed
> > these days.  But it is a good idea to have a loop that will start
> > it if/when it dies.)
> Simplest way to write that would be... another scheme process that
> starts the web server (using "system") synchronously in a loop?

I usually write a quick script that looks like this:

  while true; do
    mzscheme $HOME/foo/blah.ss
    sleep 1

which I run from a terminal in a vnc session.  (When there's an error,
the sleep makes it more convenient to abort the loop, and prevents
retrying it too fast.)  It should be possible to just start such a
script in the background and logout.  Some shells will warn you that
you have some background process, but will still logout when you try
again immediately (that is, two logouts commands without running
something else between them).

Of course the shell can't do much with that except redirect its IO to
/dev/null, and you'll need to look for the process when you log in
again -- so you'll want some additional stuff, like redirect outputs
to a log file (no need to redirect the input since you're not using it
anyway), record the process id of the current script, and if you want
to leave the whole thing running behind you, record the process id of
the loop too.  Something like this (untested) script should work:

  echo "$$" > /tmp/BLAH-LOOP-PID
  while true; do
    mzscheme x.ss >> /tmp/BLAH-LOG 2>&1 &
    echo "$blahpid" > /tmp/BLAH-CURRENT-PID
    wait "$blahpid"
    sleep 1

[You could obviously do the whole thing in mzscheme too, I just tend
to do the above since I often play with mzscheme itself...]

          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
                    http://barzilay.org/                   Maze is Life!

Posted on the users mailing list.