Jump to page: 1 2
Thread overview
Infinite loop not working DMD2
Jun 02, 2011
Guillermo Estrada
Jun 02, 2011
Brad Roberts
Jun 02, 2011
Guillermo Estrada
Jun 02, 2011
Ali Çehreli
Jun 02, 2011
Guillermo Estrada
Jun 02, 2011
Jonathan M Davis
Jun 02, 2011
Guillermo Estrada
Jun 02, 2011
Guillermo Estrada
Jun 02, 2011
Jonathan M Davis
Jun 02, 2011
Guillermo Estrada
June 02, 2011
Hi, been developing in D a lot but first time in news groups, I thought this might be the place.

I'm trying to make a fork bomb in D (of course no fork cause target its windows platform) but anyway. I did one a while ago using D1 and Tango and all ran perfectly, I'm trying to migrate my whole dev to D2 and Phobos (reading Andrei's book) but this one does not work.

import std.process;

void main(string[] args) {
	while( true ) {
		execv(args[0], null);
	}
}

It spawns one after the other but just once, it always exits the father process, if u comment the execv line, program stays in the infinite loop as expected. any insight?
June 02, 2011
On 6/2/2011 8:43 AM, Guillermo Estrada wrote:
> Hi, been developing in D a lot but first time in news groups, I thought this might be the place.
> 
> I'm trying to make a fork bomb in D (of course no fork cause target its windows platform) but anyway. I did one a while ago using D1 and Tango and all ran perfectly, I'm trying to migrate my whole dev to D2 and Phobos (reading Andrei's book) but this one does not work.
> 
> import std.process;
> 
> void main(string[] args) {
> 	while( true ) {
> 		execv(args[0], null);
> 	}
> }
> 
> It spawns one after the other but just once, it always exits the father process, if u comment the execv line, program stays in the infinite loop as expected. any insight?

The exec* family of functions cause the new app to replace the current process.  So after the execv, the loop doesn't exist.
June 02, 2011
> The exec* family of functions cause the new app to replace the
current process.  So after the execv, the loop doesn't exist.

Any way to spawn the process without killing himself?
June 02, 2011
On 06/02/2011 08:51 AM, Guillermo Estrada wrote:
>> The exec* family of functions cause the new app to replace the
> current process.  So after the execv, the loop doesn't exist.
>
> Any way to spawn the process without killing himself?

Would std.process.system or std.process.shell work?

Ali

June 02, 2011
== Quote from Ali Çehreli (acehreli@yahoo.com)'s article
> On 06/02/2011 08:51 AM, Guillermo Estrada wrote:
> >> The exec* family of functions cause the new app to replace the
> > current process.  So after the execv, the loop doesn't exist.
> >
> > Any way to spawn the process without killing himself?
> Would std.process.system or std.process.shell work?
> Ali

Well, std.process.system does not wok as intended because if you kill the parent process all children die. std.process.shell works and does what it should but spawning a cmd on each request, for a dirty quick fork bomb well, it's the same, but there should be a way in phobos to spawn process and detach them or even have control over them and close them like in tango.sys.Process, without having to go to the std.c.* libs. Thnx for the help :D
June 02, 2011
On 2011-06-02 08:59, Ali Çehreli wrote:
> On 06/02/2011 08:51 AM, Guillermo Estrada wrote:
> >> The exec* family of functions cause the new app to replace the
> > 
> > current process.  So after the execv, the loop doesn't exist.
> > 
> > Any way to spawn the process without killing himself?
> 
> Would std.process.system or std.process.shell work?

If they were called in spawned threads. What he really wants is fork though, I believe (it _is_ a _fork_ bomb after all), but I'm not sure how safe that is or isn't to call in D, since I don't know how that affects the state of the druntime. It's probably okay, since you then have two, completely separate processes, but I don't know. Regardless, you'd have to be calling the C fork, because I don't believe that druntime or Phobos provide any kind of wrapper for fork.

- Jonathan M Davis
June 02, 2011
On 2011-06-02 09:14, Guillermo Estrada wrote:
> == Quote from Ali Çehreli (acehreli@yahoo.com)'s article
> 
> > On 06/02/2011 08:51 AM, Guillermo Estrada wrote:
> > >> The exec* family of functions cause the new app to replace the
> > > 
> > > current process.  So after the execv, the loop doesn't exist.
> > > 
> > > Any way to spawn the process without killing himself?
> > 
> > Would std.process.system or std.process.shell work?
> > Ali
> 
> Well, std.process.system does not wok as intended because if you kill the parent process all children die. std.process.shell works and does what it should but spawning a cmd on each request, for a dirty quick fork bomb well, it's the same, but there should be a way in phobos to spawn process and detach them or even have control over them and close them like in tango.sys.Process, without having to go to the std.c.* libs. Thnx for the help :D

Okay. I just glanced at std.process, and I'd suggest trying spawnvp. It looks like it ends up calling fork, so it'll probably work. I haven't tried it though and don't know anything about the function beyond what's in the code.

Also, just because there _should_ be a way for there to do something in druntime or Phobos doesn't mean that there _is_ a way. There's plenty that you still have to call C functions for, if nothing else because it takes time to add all of the relevant features, and not all of the relevant features are always remembered by the Phobos developers. So, if you can't find something that really seems like it should be in Phobos, open an enhancement request on it on bugzilla: d.puremagic.com/issues/

- Jonathan M Davis
June 02, 2011
== Quote from Jonathan M Davis (jmdavisProg@gmx.com)'s article
> On 2011-06-02 09:14, Guillermo Estrada wrote:
> > == Quote from Ali Çehreli (acehreli@yahoo.com)'s article
> >
> > > On 06/02/2011 08:51 AM, Guillermo Estrada wrote:
> > > >> The exec* family of functions cause the new app to replace
the
> > > >
> > > > current process.  So after the execv, the loop doesn't
exist.
> > > >
> > > > Any way to spawn the process without killing himself?
> > >
> > > Would std.process.system or std.process.shell work?
> > > Ali
> >
> > Well, std.process.system does not wok as intended because if you kill the parent process all children die. std.process.shell
works
> > and does what it should but spawning a cmd on each request, for
a
> > dirty quick fork bomb well, it's the same, but there should be a
way
> > in phobos to spawn process and detach them or even have control
over
> > them and close them like in tango.sys.Process, without having to
go
> > to the std.c.* libs. Thnx for the help :D
> Okay. I just glanced at std.process, and I'd suggest trying
spawnvp. It loo
> ks
> like it ends up calling fork, so it'll probably work. I haven't
tried it
> though and don't know anything about the function beyond what's in
the code.
> Also, just because there _should_ be a way for there to do
something in
> druntime or Phobos doesn't mean that there _is_ a way. There's
plenty that
> you
> still have to call C functions for, if nothing else because it
takes time t
> o
> add all of the relevant features, and not all of the relevant
features are
>
> always remembered by the Phobos developers. So, if you can't find
something
>
> that really seems like it should be in Phobos, open an enhancement
request
> on
> it on bugzilla: d.puremagic.com/issues/
> - Jonathan M Davis

Johnathan, just yesterday I was at github checking exactly the same thing, spawnvp() is not documented and still on development, but it seems it just call the underlying std.c.process.spawnvp function, either way, spawnvp in either P_NOWAIT or P_NOWAITO modes will spawn child process... so killing the father is the case of calling system(args[]) but I'll have to test it. Thnx for the ideas.
June 02, 2011
> So, if you can't find something that really seems like it should
> be in Phobos, open an enhancement request on it on bugzilla:
> d.puremagic.com/issues/
> Jonathan M Davis

As expected spawnvp() creates child process that exit with the father,
just as system(). exec*() replaces the parent process, the only one I
can use is shell() that actually opens a cmd with the process
(detached) and expects the output, so in any other use shell() is not
a viable option. Gonna keep trying, and I will create an enhacement
request as you propose, Thnx.
June 02, 2011
On Thu, 02 Jun 2011 11:43:50 -0400, Guillermo Estrada <phrzn@live.com> wrote:

> Hi, been developing in D a lot but first time in news groups, I
> thought this might be the place.
>
> I'm trying to make a fork bomb in D (of course no fork cause target
> its windows platform) but anyway. I did one a while ago using D1 and
> Tango and all ran perfectly, I'm trying to migrate my whole dev to
> D2 and Phobos (reading Andrei's book) but this one does not work.
>
> import std.process;
>
> void main(string[] args) {
> 	while( true ) {
> 		execv(args[0], null);
> 	}
> }
>
> It spawns one after the other but just once, it always exits the
> father process, if u comment the execv line, program stays in the
> infinite loop as expected. any insight?

std.process is woefully unmaintained.  Lars K is developing a new version, and I am really really late getting a windows version to him so it can be included in phobos.  It includes simple methods to create a sub-process, which should solve your issue.

I think this shall be my next "Spare time" project for D.  Sorry about this, Lars.

-Steve
« First   ‹ Prev
1 2