fork

What's the best way to duplicate fork() in windows?

How do I implement some logic that will allow me to duplicate the functionality on windows that I have on linux with fork() using python? I'm specifically trying to execute a method on the SAPI Com component, while continuing the other logic in the main thread without blocking or waiting. ...

How can I fork a background processes from a Perl CGI script on Windows?

I've had some trouble forking of processes from a Perl CGI script when running on Windows. The main issue seems to be that 'fork' is emulated when running on windows, and doesn't actually seem to create a new process (just another thread in the current one). This means that web servers (like IIS) which are waiting for the process to fini...

fork() as an argument

Usually when I need to fork in C, I do something like this: pid_t p = fork(); if(p == 0) { /* do child stuff */ } else { /* do parent stuff and pray there wasn't an error */ } It occured to me that I could ditch the extra variable and use: if(fork() == 0) { /* child */ } else { /* parent/pray */ } Improper error handling aside, (wh...

Is there a way to have managed processes in Perl (i.e. a threads replacement that actually works)?

I have a multithreded application in perl for which I have to rely on several non-thread safe modules, so I have been using fork()ed processes with kill() signals as a message passing interface. The problem is that the signal handlers are a bit erratic (to say the least) and often end up with processes that get killed in inapropriate st...

Forking subprocesses in Perl unit tests stops prove; Test::Harness exiting

Hi, I have been trying to use the Perl utility/module "prove" as a test harness for some unit tests. The unit tests are a little more "system" than "unit" as I need to fork off some background processes as part of the test, Using the following... sub SpinupMonitor{ my $base_dir = shift; my $config = shift; my $pid = fork(); ...

Ruby %x forks on 64-bit Linux, but not on 32, and only with specific syntax

Here's some Ruby code: puts %x{ pstree #{$$} } # never forks puts %x{ pstree '#{$$}' } # forks on amd64 only On 32-bit Ubuntu Dapper, I get this output: t.rb---pstree t.rb---pstree Which makes sense to me. But on 64-bit Ubuntu Hardy, I get this: t.rb---sh---pstree t.rb---pstree What's being shown here is that Ruby forks befor...

How do you share data between a parent and forked child process in Python?

I'm pretty sure one would do this using the os.plock(op) function, but I have no idea how. Also, if there's a better way, I'd be grateful to find out. Code snippets are very welcome. Thanks! ...

For ruby/webrick, I need windows to recognize shebang (#!) notation.

(Bear with me, I promise this gets to shebang and windows.) I have about the simplest of WEBRick servers put together: require 'webrick' include WEBrick s = HTTPServer.new(:Port=>2000, :DocumentRoot=>Dir::pwd) s.start Couldn't be simpler. This basic server does accept http connections (firefox, internet exploder, wget, TELENT) and ...

How to make child process die after parent exits?

Suppose I have a process which spawns exactly one child process. Now when the parent process exits for whatever reason (normally or abnormally, by kill, ^C, assert failure or anything else) I want the child process to die. How to do that correctly? Some similar question on stackoverflow: (asked earlier) http://stackoverflow.com/ques...

Java - C-Like Fork?

Is it possible to do a "C like" fork in java, using an new independent jvm process ? How? ...

How do I tell valgrind to memcheck forked processes?

I have a process x that I want to check for leaks with valgrind. The problem is that x is run by y, and y in turn is run by z. I can't run x standalone because y and z setup the environment for x, such as environment variables, command line switches, files needed by x etc. Is there any way I can tell valgrind to run on z but to fol...

Is process forking in PHP / Apache a good idea?

I'm writing a simple application in PHP which needs to occasionally carry out a fairly intensive set of MySQL updates. I don't particularly want this to cause a delay for the user, so I'm wondering about using pcntl_fork(). I'm not sure how this really works though: will the child process continue running after the parent process finis...

CherryPy for a webhosting control panel application

For quite a long time I've wanted to start a pet project that will aim in time to become a web hosting control panel, but mainly focused on Python hosting -- meaning I would like to make a way for users to generate/start Django/ other frameworks projects right from the panel. I seemed to have found the perfect tool to build my app with i...

How can I enforce a maximum amount of forked children?

EDIT: I've tagged this C in a hope to get more response. It's more the theory I'm interested in than a specific language implementation. So if you're a C coder please treat the following PHP as pseudo-code and feel free to respond with an answer written in C. I am trying to speed up a PHP CLI script by having it execute its tasks in p...

Avoiding a fork()/SIGCHLD race condition

Please consider the following fork()/SIGCHLD pseudo-code. // main program excerpt for (;;) { if ( is_time_to_make_babies ) { pid = fork(); if (pid == -1) { /* fail */ } else if (pid == 0) { /* child stuff */ print "child started" exit } else { ...

How do you clear output buffers when the program forks?

I have a program that writes to a FILE *cgiOut and just after it has written to the stream, I need to fork and run a background process. The trouble is that after the fork, the FILE * stream seems to flush out sometimes and I get duplicated output (after the fork, all open files are closed which I guess causes the buffers to be flushed)...

Starting and stopping a forked process

Is it possible for a parent process to start and stop a child (forked) process in Unix? I want to implement a task scheduler (see here) which is able to run multiple processes at the same time which I believe requires either separate processes or threads. How can I stop the execution of a child process and resume it after a given amoun...

Are child processes created with fork() automatically killed when the parent is killed?

I'm creating child processes with fork() in C/C++. When the parent process ends (or is killed for some reason) I want all child processes to be killed as well. Is that done automatically by the system? Or I have to do it myself? Thanks. Pre-existing similar questions: http://stackoverflow.com/questions/269494/how-can-i-cause-a-chil...

Profiling a multi-process program

I'd like to profile a program that forks and spawns several child processes. I want to see how much time is spent in some of the functions. What profiler can handle this job? ...

Broken pipes in C -- pipe(), fork(), exec() program

Hello, I need to write a simple program: There will be a Parent and a few programs [children] (started via execl in Parent). Children communicate to one another in this way: Child I sens to Parent number J, Parent sends a message (something like -- "there is a message to you") to J, J send to Parent number K etc. etc. And there is a pr...