fork

Problem with fork exec kill when redirecting output in perl

I created a script in perl to run programs with a timeout. If the program being executed takes longer then the timeout than the script kills this program and returns the message "TIMEOUT". The script worked quite well until I decided to redirect the output of the executed program. When the stdout and stderr are being redirected, the p...

How to handle inputs in a C shell program during exec

I am currently writing my own shell program. This simple shell can just execute commands. When executing commands like vi or calc which require input from the terminal , the command is getting executed and is waiting for the input from the user. But I am unable to give any input on the screen. How should the input be handled during the...

problem with fork()

I'm writing a shell which forks, with the parent reading the input and the child process parsing and executing it with execvp. pseudocode of main method: do{ pid = fork(); print pid; if (p<0) { error; exit; } if (p>0) { wait for child to finish; read input; } else { call function to parse input; exit; } }while condition return; ...

perl fork doesn't work properly when run remotely (via ssh)

I have a perl script, script.pl which, when run, does a fork, the parent process outputs its pid to a file then exits while the child process outputs something to STOUT and then goes into a while loop. $pid = fork(); if ( ! defined $pid ) { die "Failed to fork."; } #Parent process elsif($pid) { if(!open (PID, ">>running_PIDs")...

Java file management on process forking

My guesses were wrong, and had nothing to do with the answer. This question is no longer valid. See my answer. Sorry about this poor question. Tl;dr Version Why can't a Java process find a certain file, until another process – the process that created that file – has finished executing. Can this be worked around? Longer Version I hav...

How can I run a program in the background (non blocking) with php?

Hi, I want to run a shell script in php, but this shell script takes a long time to execute (it has sleep in it), I don't want the web server to block when executing this script. I tried exec() and shell_exec() in php but the server stops until the shell script finishes! I thought of doing fork in the shell script itself but I don't kn...

Prevent fork() from copying sockets

I have the following situation (pseudocode): function f: pid = fork() if pid == 0: exec to another long-running executable (no communication needed to that process) else: return "something" f is exposed over a XmlRpc++ server. When the function is called over XML-RPC, the parent process prints "done closing...

Using subprocess to find out when a process ends

I wish to sequentially run some c scripts that fork their own processes (in a new command line window) and give the "Press any key to continue..." when they are completed. Technically, it is a special compiler. It pops up with acommand line window and tells me whether the compile was successful or not. But that command line window for...

C: Multiple forks

Hi I need to use shared memory and fork to do this: Multipling random 512x512 matrixes using 4 processes and shared memory. I know how to fork one child but How can I fork 4 processes that do 1/4 of work? Thanks ...

C - iterative multiple forks

Hi I need to make 4 forks 1000 times. I wrote this but it runs forever: #include <stdio.h> #include <stdlib.h> #include <time.h> #include <sys/types.h> #define N 512 void chunk0(void); void chunk1(void); void chunk2(void); void chunk3(void); double get_time(void); void main(void) { int i,j,k,iterations=0; unsigned in...

C - fork - wait problem

I wrote this code: #include <stdio.h> #include <stdlib.h> #include <time.h> #include <sys/types.h> #include <sys/shm.h> #define N 512 void chunk0(unsigned int *s, unsigned int *a, unsigned int *b, int MID,int it); void chunk1(unsigned int *s, unsigned int *a, unsigned int *b, int MID,int it); void chunk2(unsigned int *s, unsig...

Signals in fork

What is signal behavior in the fork. Should all signals are inherited in fork If not then which one and why? ...

ruby: How do i get the number of subprocess(fork) running

I want to limit the subprocesses count to 3. Once it hits 3 i wait until one of the processes stops and then execute a new one. I'm using Kernel.fork to start the process. How do i get the number of running subprocesses? or is there a better way to do this? ...

Python Popen.waitpid returns "[Errno 10] No child processes"

I have a working Python script that executes an external command and calls Popen.communicate(). However when I call this script from a C process, it fails in os.waitpid() with "[Errno 10] No child processes". Why? This looks like a certain bug in Python, but I'm not using threads. The C process forks, changes its UID, GID, and calls se...

ProcessBuilder - Start another process / JVM - HowTo?

I'm writing a network app, where each Client has a Singleton ClientManager. For testing, I would like to create several clients (each in their own VM / process) without starting the program by hand n-times. The following two questions on stackoverflow already describe how-to do that: Is this really the best way to start a second JVM f...

Spawn a process with php doesn't work

Hi, I tried to start a background process with php, for that, I added a & at bottom on exec function but after a few days it stop working. Basically If i have file 1.php with: <?php var_dump(exec('/home/2.php > /home/2.output 2>&1 &')); And file 2.php with: <?php sleep(5); echo "Fill\n"; Running file 1.php, it return an empty st...

ProcessBuilder - Start another process / JVM in Scala - HowTo?

I already handled to start another VM in Java. See ProcessBuilder - Start another process / JVM - HowTo? For some reason, I can't manage to do the same in Scala. Here's my code object NewProcTest { def main(args :Array[String]) { println("Main") // val clazz = classOf[O3] val clazz = O4.getClass Proc.spawn(clazz, true...

C fork/exec with non-blocking pipe IO

This seems to be a fairly common thing to do, and I've managed to teach myself everything that I need to make it work, except that I now have a single problem, which is defying my troubleshooting. int nonBlockingPOpen(char *const argv[]){ int inpipe; pid_t pid; /* open both ends of pipe nonblockingly */ pid = fork(); ...

basic python server using spawn/threads....

Hi. Got a problem that I'm facing. and it should be pretty simple. I have an app that places data into a dir "A". The data will be a series of files. I want to have a continually running server, that does a continual look at the dir, and on seeing a completed file in the dir, the server spawns/forks/creates a thread (not sure of the e...

Python fork-exec problem, child process output goes to same place as parent process.

Try the code below with: python fork.py and with: python fork.py 1 to see what it does. #!/usr/bin/env python2 import os import sys child_exit_status = 0 if len(sys.argv) > 1: child_exit_status = int(sys.argv[1]) pid = os.fork() if pid == 0: print "This is the child" if child_exit_status == 0: os.execl('/usr/bin/w...