fork

How can I share a database connection across a forked process in Perl?

I made the following programs in Perl before: my $db = DBconnection with DB2 if ($pid = fork()) { #parent } else { #child $db->execute("SELECT ****"); exit; } wait(); $db->execute("SELECT ****"); I thought that it waited for the end of the child process to have wanted to do it and would operate it for DB by a pro-pro...

Multiple child process

hi, can someone help me about how to create multiple child processes which have the same parent in order to do "some" part of particular job? for example, an external sorting algorithm which is applied with child processes; each child process sorts a part of data and finally the parent merges them.. EDIT: Maybe I should mention the f...

Multiple child process + reading from a stream

hi, referring to my last question (http://stackoverflow.com/questions/876605/multiple-child-process), i am now trying to make an external sorting implementation using multiple child process. ... fp = fopen(pathname, "r"); // open inputfile in r mode fgets(trash, 10, fp); // ignore first line for (i=0; i<numberOfProcess; ++i) { #ifdef...

How to exit a child process and return its status from execvp()?

In my simple custom shell I'm reading commands from the standard input and execute them with execvp(). Before this, I create a fork of the current process and I call the execvp() in that child process, right after that, I call exit(0). Something like this: pid = fork(); if(pid == -1) { perror("fork"); exit(1); } if(pid == 0) ...

Portable way to pass file descriptor between different processes

On most UNIX systems passing an open file between processes can be easily done for child/parent processes by fork(); however I need to share a fd "after" the child was already forked. I've found some webpages telling me that sendmsg() may work for arbitary processes; but that seems very OS dependent and complex. The portlisten seems lik...

Having trouble with fork(), pipe(), dup2() and exec() in C

Here's my code: #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <wait.h> #include <readline/readline.h> #define NUMPIPES 2 int main(int argc, char *argv[]) { char *bBuffer, *sPtr, *aPtr = NULL, *pipeComms[NUMPIPES], *cmdArgs[10]; int fdPipe[2], pCount, aCount, i, status, lPids[NUMPIPES]; pid_t pid; ...

Create a new independent process from another C process

Two C executables A and B exist. A and B communicate to each other through a socket. B can be started independently or through A. If B is started first and A is started next, then A and B start properly without issues. Even if A is restarted, then there are no issues. If B is started through A, then A and B starts properly. But here ...

Why isn't my Perl program reaping children processes after fork?

I have been trying to write a bare-bones ping scanner using Perl for internal use. Since it scans a 24-bit CIDR network the script takes too long to run if it runs in a single thread. I have tried adding fork functionality to speed up the process but my first attempt was taking pretty much the same time since there was only one child pro...

Does this multiple pipes code in C makes sense?

I've created a question about this a few days. My solution is something in the lines of what was suggested in the accepted answer. However, a friend of mine came up with the following solution: Please note that the code has been updated a few times (check the edit revisions) to reflect the suggestions in the answers below. If you intend...

How can I fork a Perl CGI program to hive off long-running tasks?

I am writing a Bulk Mail scheduler controlled from a Perl/CGI Application and would like to learn abut "good" ways to fork a CGI program to run a separate task? Should one do it at all? Or is it better to suffer the overhead of running a separate job-queue engine like Gearman or TheSchwartz as has been suggested recently. Does the answer...

Portable way to "fork()" in QT application?

Say, i need to run a bunch of code that is prone to crash so i need to run it on a different process. Typically i'd do it something like this: pid = fork(); if (pid == -1) { std::cout << "Cant Spawn New Thread"; exit(0); } else if (pid == 0) { std::cout << "Im a child that will crash\n"; char *foo = (char *) 0xffff...

What is the purpose of fork()?

In many programs and man pages of Linux, I have seen code using fork(). Why do we need to use fork() and what is its purpose? ...

What is the closest thing windows has to fork()?

I guess the question says it all. I want to fork on windows. What is the most similar operation and how do I use it. ...

Any better alternative to fork() and then execvp(" gcc program.c ") ?

Hi, The following code segment takes more time (5s) when it is run first time and takes less time(250ms) on consecutive runs. Is there any better way to execute gcc. int pid,status; char * argv[] = {"gcc","program.c",NULL}; if(!(pid=fork())){ execvp("gcc",argv); } while(pid!=wait(&status)){ //do nothing } ...

fork and existing threads ?

On a linux system, does the child process view the existing threads the same way as the parent process ? int main() { //create thread 1 . . . int child_pid = fork(); if ( 0 == child_pid) { .. } else { .. } Since the whole address space is copied for the child process, what happens to the state of the threads. What if the thread 1 in...

Fork and sighandlers

If I setup sighandler and then do a fork. Will the child process also inherit the sighandlers? ...

Linux Process Spawn/Creation Trigger

Hello, I am attempting to programmatically track the processes a linux user is currently running. Is it possible to be notified when a user has fork-ed or exec-ed a new process, or is the only solution to perpetually poll the process list for new processes. Thanks, Ken ...

Monitoring Children Forked using PHP

Hi all, I have a problem, I use pcntl_fork to fork a process in PHP, $pid = pcntl_fork(); if ($pid == -1) { die('could not fork'); } else if ($pid) { // we are the parent pcntl_wait($status); //Protect against Zombie children } else { pcntl_exec("/path/to/php/script"); echo "Could not Execute..."; } I am trying to figure out a w...

Run a ffmpeg process in the background

I am wanting to use ffmpeg to convert video to .flv in php. Currently I have this working, but it hangs the browser until the file is uploaded and is finished. I have been looking at the php docs on how to run an exec() process in the background, while updating the process using the returned PID. Here is what I found: //Run linux com...

fork in multi-threaded program

I've heard that mixing forking and threading in a program could be very problematic, often resulting with mysterious behavior, especially when dealing with shared resources, such as locks, pipes, file descriptors. But I never fully understand what exactly the dangers are and when those could happen. It would be great if someone with expe...