For Programmers: Free Programming Magazines  


Home > Archive > Fortran > May 2004 > fork in Fortran









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author fork in Fortran
Shuo Yang

2004-05-12, 9:09 pm

Is there a way to fork processes in Fortran? Thanks,

Shuo Yang

2004-05-12, 9:09 pm

Shuo Yang wrote:
> Is there a way to fork processes in Fortran? Thanks,
>

I am using a f77 compiler.

Kevin G. Rhoads

2004-05-12, 9:09 pm

>Is there a way to fork processes in Fortran?

Not with stnadard F77 -- however, it can often be
done by using C rtl routines -- but that is very
platform specific.
Shuo Yang

2004-05-12, 9:09 pm

Kevin G. Rhoads wrote:
>
>
> Not with stnadard F77 -- however, it can often be
> done by using C rtl routines -- but that is very
> platform specific.


I can use date() function in my platform, but not fork(). Why?
I am trying to wrap the C fork() to the fortran routine
fork_(int* pid)
{
pid = fork();
}

Is this doable?

Richard Maine

2004-05-12, 9:09 pm

Shuo Yang <yang22@purdue.edu> writes:

> Is there a way to fork processes in Fortran? Thanks,


Short answer: No, but...

Side comment: And, by the way, there isn't a way in C or most any
other language also. Few languages deal with such things as a
language issue. Ada is a rare exception. If you think that C, for
example, has a way to fork processes, then you are confusing the C
language with Unix system calls - a relatively common confusion,
which is why I mention it in particular.

Longer answer: This has more to do with the operating system than the
language. As such, any answer is a function of the particular
operating system and compiler. In particular, "forking processes" is
a Unix concept. It also has lots of subtleties. In order to make
constructive use of it, you need to be able to understand the
Unix forking process and how it applies to your particular
application. Most of this has little to do with the language.
If you can figure out what operating system calls would do what
you want, then it is usually possible to do those OS calls
from Fortran, sometimes with a bit of work (which should be
simpler and more portable in f2003, but it is possible and
regularly done today).

I have personally used forking in a server written primarily in
Fortran. However, the odds of my application being applicable to
whatever you are trying to do are poor - too poor to be worth
bothering to post and explain it, particularly since you didn't
mention the word "server", which is fundamental to the whole reason
my application was forking. (No, I'm not just going to post it
without explanation of its context - that would be guaranteed to be
worthless, but properly explaining it would take a bit of work.)

--
Richard Maine | Good judgment comes from experience;
email: my first.last at org.domain | experience comes from bad judgment.
org: nasa, domain: gov | -- Mark Twain
James Giles

2004-05-12, 9:09 pm

Shuo Yang wrote:
> Shuo Yang wrote:
> I am using a f77 compiler.



It's usually the same way you fork a process in any other
language: a procedure call to the appropriate implementation
dependent procedure. This is not part of any language standard,
but part of the system specification. Some systems don't
provide a language-neutral interface, and some don't provide
separate bindings for all languages either :-(. You may need
to use a bridge routine written in some language other than
Fortran.

With more specifics as to your system and compiler someone
could probably answer your question more fully.

--
J. Giles


Richard Maine

2004-05-12, 9:09 pm

Shuo Yang <yang22@purdue.edu> writes:

> I can use date() function in my platform, but not fork(). Why?


Because someone evidently already did a date wrapper for you,
but didn't do a fork one. Presumably because date() is a
reasonably common and simple f77 extension desire (though
f90 has the standard date_and_time), while fork() is far
more esoteric.

> I am trying to wrap the C fork() to the fortran routine
> fork_(int* pid)
> {
> pid = fork();
> }
>
> Is this doable?


In general, yes, but I didn't try to study your wrapper in
detail. The usage of fork involves enough subtlety that I
don't think I'll try to help with the exact coding....
mostly because that would get me stuck with helping to
debug things that I don't want to get into.

So I'll stick with the simple answer that yes, something
along that line will probably work, though it is possible
that particular compilers in particular environments might
have problems with it. I'm not even thinking of any
problems in particular - just warning that this kind of
thing is system-specific enough that theye may be issues
that vary among compilers.

--
Richard Maine | Good judgment comes from experience;
email: my first.last at org.domain | experience comes from bad judgment.
org: nasa, domain: gov | -- Mark Twain
Madhusudan Singh

2004-05-12, 9:09 pm

On Monday 10 May 2004 15:22, Shuo Yang (yang22@purdue.edu) held forth in
comp.lang.fortran (<c7okpk$bj2$1@mozo.cc.purdue.edu> ):

> Is there a way to fork processes in Fortran? Thanks,


You might want to look into fortranposix :

http://www.sourceforge.net/projects/fortranposix

It does not implement fortran_fork() yet, but it does offer fortran_popen()
if that is what you want to do.
Shuo Yang

2004-05-12, 9:09 pm

It helps a lot. Thank you.
Shuo Yang

Richard Maine wrote:
> Shuo Yang <yang22@purdue.edu> writes:
>
>
>
>
> Short answer: No, but...
>
> Side comment: And, by the way, there isn't a way in C or most any
> other language also. Few languages deal with such things as a
> language issue. Ada is a rare exception. If you think that C, for
> example, has a way to fork processes, then you are confusing the C
> language with Unix system calls - a relatively common confusion,
> which is why I mention it in particular.
>
> Longer answer: This has more to do with the operating system than the
> language. As such, any answer is a function of the particular
> operating system and compiler. In particular, "forking processes" is
> a Unix concept. It also has lots of subtleties. In order to make
> constructive use of it, you need to be able to understand the
> Unix forking process and how it applies to your particular
> application. Most of this has little to do with the language.
> If you can figure out what operating system calls would do what
> you want, then it is usually possible to do those OS calls
> from Fortran, sometimes with a bit of work (which should be
> simpler and more portable in f2003, but it is possible and
> regularly done today).
>
> I have personally used forking in a server written primarily in
> Fortran. However, the odds of my application being applicable to
> whatever you are trying to do are poor - too poor to be worth
> bothering to post and explain it, particularly since you didn't
> mention the word "server", which is fundamental to the whole reason
> my application was forking. (No, I'm not just going to post it
> without explanation of its context - that would be guaranteed to be
> worthless, but properly explaining it would take a bit of work.)
>


Pierre Asselin

2004-05-12, 9:09 pm

Shuo Yang <yang22@purdue.edu> wrote:

> [ ... ]
> I am trying to wrap the C fork() to the fortran routine
> fork_(int* pid)
> {
> pid = fork();
> }


Did you mean "*pid= fork()" ?

--
pa at panix dot com
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com