Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows exec() after fork() replaces all pseudo-processes #6999

Open
p5pRT opened this issue Dec 22, 2003 · 5 comments
Open

Windows exec() after fork() replaces all pseudo-processes #6999

p5pRT opened this issue Dec 22, 2003 · 5 comments

Comments

@p5pRT
Copy link

p5pRT commented Dec 22, 2003

Migrated from rt.perl.org#24731 (status was 'open')

Searchable as RT24731$

@p5pRT
Copy link
Author

p5pRT commented Dec 22, 2003

From beissinger.tobias@siemens.com

Hello,

I think there is a bug in fork in windows server 2003 64-Bit on an IA64 Platform (Itanium 2).
I tried these perls​: ActiveState 5.8, Stable 5.8, Developer 5.9

The code affected is​:

if ($pid=fork()) {
  #mainprog
}
else {
  exec "perl $0"; #start my prog again and "close" the child immediatly
}

I use this code to generate multiple sessions on a database (it's part of my diploma thesis).

PROBLEM​:
The exec also kills the #mainprog section.

The code works fine and as expected under Suse Linux 8.0, 8.1, 8.2, HP-UX 11.20, 11.22, 11.23, Windows XP Professional SP1.
I would prefer exec rather than system because I want totally independent instances of my testscript (Many different users do many different actions). For me that's the only way to do it ( or you tell me how to fork up to 500 instances).

I also tried to encapsulate the exec in a "sub restart" and to start this as a thread (use thread, thread->new...), but it has the same effect, even if I additionally fork in that sub​:

Sub restart {
  if ($pid=fork()) {
  return; } #ok, that's unorthodox, but it worked
  else {exec $0; }
}
$t=Thread->new(\&restart)

Mit freundlichen Grüßen/ Kind regards

Tobias Beissinger
Siemens VDO Automotive AG
SV IO ML
RbgS/O10/2/A15.1
Tel.​: 0941/ 790 - 9823

@p5pRT
Copy link
Author

p5pRT commented Dec 30, 2003

From @iabyn

On Mon, Dec 22, 2003 at 07​:30​:48AM -0000, Beissinger Tobias wrote​:

# New Ticket Created by Beissinger Tobias
# Please include the string​: [perl #24731]
# in the subject line of all future correspondence about this issue.
# <URL​: http​://rt.perl.org/rt3/Ticket/Display.html?id=24731 >

Hello,

I think there is a bug in fork in windows server 2003 64-Bit on an IA64 Platform (Itanium 2).
I tried these perls​: ActiveState 5.8, Stable 5.8, Developer 5.9

The code affected is​:

if ($pid=fork()) {
#mainprog
}
else {
exec "perl $0"; #start my prog again and "close" the child immediatly
}

I use this code to generate multiple sessions on a database (it's part of my diploma thesis).

PROBLEM​:
The exec also kills the #mainprog section.

The code works fine and as expected under Suse Linux 8.0, 8.1, 8.2, HP-UX 11.20, 11.22, 11.23, Windows XP Professional SP1.

I don't "do" Windows, so the following comments are speculative.

Since Windows doesn't support fork() at the OS level, Perl has to
emulate it by creating additional threads in the main process. In UNIX
at least, exec() replaces the whole process, not just the current thread,
and if Window's exec() behaves similarly, then that would explain what you
are seeing. However, I'm slightly puzzled by the fact that you claim
XP works. Any Windows experts here want to comment?

Dave.

--
Monto Blanco... scorchio!

@p5pRT
Copy link
Author

p5pRT commented Dec 30, 2003

From nick@ing-simmons.net

Dave Mitchell <davem@​fdisolutions.com> writes​:

PROBLEM​: The exec also kills the #mainprog section.

The code works fine and as expected under Suse Linux 8.0, 8.1, 8.2, HP-UX
11.20, 11.22, 11.23, Windows XP Professional SP1.

I don't "do" Windows, so the following comments are speculative.

Since Windows doesn't support fork() at the OS level, Perl has to emulate it
by creating additional threads in the main process. In UNIX at least, exec()
replaces the whole process, not just the current thread, and if Window's
exec() behaves similarly, then that would explain what you are seeing.
However, I'm slightly puzzled by the fact that you claim XP works. Any Windows
experts here want to comment?

My expertise is rusting rapidly, but AFAIK to fake fork you need threads.
The win32/makefile* have comments to that effect, and I believe that is
the default these days.

I don't see how it can work on XP.

Note that cygwin pseudo-OS has its own fork() faking...

@p5pRT
Copy link
Author

p5pRT commented Sep 30, 2012

From @jkeenan

On Sun Dec 21 23​:30​:47 2003, beissinger.tobias@​siemens.com wrote​:

Hello,

I think there is a bug in fork in windows server 2003 64-Bit on an
IA64 Platform (Itanium 2).
I tried these perls​: ActiveState 5.8, Stable 5.8, Developer 5.9

The code affected is​:

if ($pid=fork()) {
#mainprog
}
else {
exec "perl $0"; #start my prog again and "close" the child
immediatly
}

I use this code to generate multiple sessions on a database (it's part
of my diploma thesis).

PROBLEM​:
The exec also kills the #mainprog section.

The code works fine and as expected under Suse Linux 8.0, 8.1, 8.2,
HP-UX 11.20, 11.22, 11.23, Windows XP Professional SP1.
I would prefer exec rather than system because I want totally
independent instances of my testscript (Many different users do
many different actions). For me that's the only way to do it ( or
you tell me how to fork up to 500 instances).

I also tried to encapsulate the exec in a "sub restart" and to start
this as a thread (use thread, thread->new...), but it has the same
effect, even if I additionally fork in that sub​:

Sub restart {
if ($pid=fork()) {
return; } #ok, that's unorthodox, but it worked
else {exec $0; }
}
$t=Thread->new(\&restart)

Mit freundlichen Gr��en/ Kind regards

Tobias Beissinger
Siemens VDO Automotive AG
SV IO ML
RbgS/O10/2/A15.1
Tel.​: 0941/ 790 - 9823

Do we have any Windows 64-bit folk who could look at this older ticket?
One of the original respondents is no longer with us.

Thank you very much.
Jim Keenan

@p5pRT
Copy link
Author

p5pRT commented Jul 6, 2016

From @dcollinsn

fork() is extremely difficult and slow to implement on Windows. Cygwin managed to pull it off - through no small effort - and even so, their implementation is quite slow. Windows effectively requires you to implement fork() through CreateProcess() and then using IPC to copy state to the new process.

For reasons (presumably efficiency), we emulate fork() on Windows using threads. In fact, perldoc perlfork even freely admits that "if the parent process is killed, all the pseudo-processes are killed as well". If we think this is worth a separate note, we can add another heading that fork-exec does not work on Windows, or add a note to for Portability Caveats section in that doc.

However, this ticket asks "do not emulate fork() using threads", so it is wishlist at best.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants