[Tutor] exec vs system (fwd)

D-Man dsh8290@rit.edu
Sun, 25 Feb 2001 18:50:45 -0500


| ---------- Forwarded message ----------
| Date: Sat, 24 Feb 2001 21:05:50 +0000
| From: Viktor Lakics <lakicsv@usa.net>
| To: Danny Yoo <dyoo@hkn.eecs.berkeley.edu>
| Subject: exec vs system
| 
| On Sat, Feb 24, 2001 at 02:10:39AM -0800, Danny Yoo wrote:
| 
| The reason I have not tried, was that I thought that the difference
| between execv and system is that exec is replacing the python
| interpreter when it is invoked. And I thought if I invoke fetchmail
| in demon mode (that is what the -d stands for) it is better to run
| it this way...
| 
| Is that right? Does it make any difference?
| 

That is right, execv will replace the current process (the python
interperter) with a new proecss (fetchmail in your case).

I don't think it makes any difference.  If you run fetchmail in daemon
mode from the command line, your shell returns to an interactive state
immediately (after reporting the PID of the fetchmail daemon).  The
way fetchmail works (basically), if you start it in daemon mode is :


pid = fork()
if pid == 0 :
    # this is the child,
    while 1 :
        get_mail()
        sleep( 1000 )
else :
    # this is the original parent, 
    # return control back to the previous process (shell, whatever)
    sys.exit( 0 )



If your script simply invokes fetchmial using os.system, you will get
the success exit value almost immediately, while the deamon runs in
the background and your script is free to terminate the python
interpreter at its leisure.  If you use execv, the interpreter will be
replaced by fetchmail, which will fork and then terminate the parent
process.

You can also start fetchmail in daemon mode by specifying it in your
fetchmailrc file.

I don't know if this is relevant/helpful at all, but I simply put
"fetchmail" in my .bash_profile file so that fetchmail is run when I
login.  I put "fetchmail --kill" (or whatever the option is, I'm not
at my linux box right now) in my .logout file so that it terminates
when I log out.  I can also run fetchmail at any time since it will
check for an already running daemon and simply wake it up if it
exists.

-D