Pierre-Charles David
11/22/2006 1:30:00 PM
2006/11/20, Paul Lutus <nospam@nosite.zzz>:
> observatory@gmail.com wrote:
>
> > Hello,
> >
> > I have a ruby (rails) cronjob.
> > When I monitor the execution of the cronjob with top, I notice that 2
> > more processes show up in there (instead of just one for my cronjob).
> >
> > My cronjob captures the output of running a python script (with the
> > `python script.py` syntax). Can this be the cause?
>
> Yes.
>
> > Why?
>
> Because the cronjob has its own process ID (1), then it needs to execute the
> Python interpreter (2) which runs the Python script (3). All separate
> processes.
No: Python does not create two processes. However, the backtick
command uses a sub-shell to execute the command line, so: cron
launches Ruby (1 process), which launches "/bin/sh -c 'python
script.py'" (1 process), which launches Python on the script (1
process). See the documentation for Kernel#` (the actual method
implementing the backtick command).
If you don"t need shell-specific features (pipes and redirections) in
the command line you execute, you can fork the Ruby process and then
call exec to *replace* that child process with python, thus bypassing
the intermediate shell. It's probably not worth the trouble though.