fork

Python: when to use pty.fork() versus os.fork()

I'm uncertain whether to use pty.fork() or os.fork() when spawning external background processes from my app. (Such as chess engines) I want the spawned processes to die if the parent is killed, as with spawning apps in a terminal. What are the ups and downs between the two forks? ...

Problem with bin/sh -i in a forked process, error: 'can't access tty, job control turned off'

I'm writing a cgi-bin program for my Sheevaplug (running the default Ubuntu install) that displays a shell in a browser page. It is a single C program that is placed in the cgi-bin folder and viewed in a browser. It automatically launches a daemon and the daemon forks an instance of the shell. The cgi-bin communicates with the daemon via...

minor issue with fork() and pipe()

I 'm writing a little program that implements pipes like they work in the shell. ie: ls -hal | sort | grep p | wc it works fine, with the minor issue that on one line, when CMD_NO=n, the comparison i biggerthan CMD_NO does not work, but i!=(CMD_NO-1) does. I'm trying to figure out why in this particular case (the line is ocmmented a...

How can I timeout a forked process that might hang?

Hi all, I am writing a Perl script that will write some inputs and send those inputs to an external program. There is a small but non-zero chance that this program will hang, and I want to time it out: my $pid = fork; if ($pid > 0){ eval{ local $SIG{ALRM} = sub { die "TIMEOUT!"}; alarm $num_secs_to_timeout; ...

Shared memory for fork

I want to create a shared memory between two process. I used fork(). A child tries to change this shared memory and mother creates another child so new child tries to change same memory so on. here is my code in C programing. (ubuntu) mylist ch=NUL; f=fork(); if(!f){ pba=shmget(KEYSHM,sizeof(char),0); /*created shared memory*/ ...

Stop users from locking up crashing Linux machine using simple C code

Hi Is there a way to prevent users from locking up a linux machine with code something along the lines of: #import <stdio.h> int main (int argc, char** argv) { while (1) fork(); } The computers in question are in a computer lab, so I can't exactly disallow compiling... but is there some way of ensuring such processes only...

Question about fork()

Hi, this is my function: void connection(int sock) // sock is a descriptor of socket { char buffer[MAX]; int n; // number of bytes read or write into a socket int f; f = fork(); if(write(sock,"HELLO\n", 5) < 0) { perror("Error: \n"); } write(sock, "\n> ",3); do { memset(buffer,'0',M...

How do you merge changes on non-master branches from a forked github repository?

In both of the following StackOverflow questions, the accepted answer describes how to merge changes from a forked repository in the situation where you fork a repo, the original repo is modified, and then you want to merge the changes made to the master branch back into your forked repo. Merging between forks in GitHub Merge changes f...

Spawning multiple processes with PHP to proccess data.

I have a queue (Amazon SQS) of data that needs to be processed, and I would like to do it with multiple processes (in PHP). I want the child workers to do something like this (pseduoish code): while(true) { $array = $queue->fetchNItems(10); // get 10 items if(!count($array)) killProcess(); foreach($array as $...

PHP: What does pcntl_fork() really do?

PHP's pcntl_fork funcion is supposed to fork a process just as the standard fork function in C. But I was wondering if this function really forks the process or if it emulates that behavior in a different way. If it really forks the process then it's clear which process that is: one of Apache's child processes. That's OK as long as Apach...

Will a PHP script maintain its session if it is run via exec?

Hello all, I would like to run a PHP script from another PHP script so that the parent comes back with a success when it initiates the child script. The parent will be initiated from the browser where I am using sessions. Will the child script be able to make use of the same session and session variables if run via exec? Thanks all fo...

start "unrelated" 64 bit app from 32 bit app

Hi, is there an elegant way to start a 64 bit process from an 32 bit compiled application? The problem is that i need to compile one part in 32bit Sparc V8 mode. The other part is written for a faster 64 bit environment (no emulation on 64bit multiplication). I want to synchronize them using semaphore and communicate via shared memory. ...

A light weight Scala fork join syntax

Despite the upcoming java 7 standard fork/join framework, I am building some helper method that is light weight in syntax for client to run code in parallel. Here is a runnable main method to illustrate the idea. import actors.Futures object ForkTest2 { def main(args: Array[String]) { test1 test2 } def test1 { v...

String copy using pipes

Hi All, i have written the following code to copy a string "hello world" to another char array using fork and pipes instead of using standard library functions or standard i/o streams. The program is compiling successfully but i am not getting any output. Even, the printf's output are not being shown. # include <string.h> # include <uni...

Fork delayed job from the app server?

Here's my simple ideal case scenario for when I'd like delayed job to run: When the first application server (whether through mongrel or passenger) starts, it'll start my delayed job workers. When the last running application server terminates, it'll kill all the delayed job workers. The first part (starting) is doable, although I'm ...

How can I keep on-the-fly application-level statistics in an application running under Apache?

I have an application running under apache that I want to keep "in the moment" statistics on. I want to have the application tell me things like: requests per second, broken down by types of request latency to make requests to various backend services via thrift (broken down by service and server) number of errors being served per sec...

fork() and printf()

As I understood fork() creates a child process by copying the image of the parent process. My question is about how do child and parent processes share the stdout stream? Can printf() function of one process be interrupted by other or not? Which may cause the mixed output. Or is the printf() function output atomic? For example: The...

socket() returns 0 C client / server app

I'm working on an application that contains several server sockets that each run in a unique thread. An external utility (script) is called by one of the threads. This script calls a utility (client) that sends a message to one of the server sockets. Initially, I was using system() to execute this external script, but we couldn't use t...

How to get return value from CHILD PROCESS?

Program calculates sum of numbers from 1 to N.. Child process calculates sum of EVEN numbers. Parent process calculates sum of odd numbers. I want to get the return value of child process in parent process. How do i do that #include<stdio.h> #include<errno.h> #include<unistd.h> #include<stdlib.h> #include<fcntl.h> int main() { int ...

Is it possible to double-fork a process in Java?

I need to double-fork vmware so it doesn't inherit the terminal ID (TTY/pts). This is what I have so far, but I can't get access to the runtime.exec process to fork another process (which removes the terminal ID). Runtime runtime = Runtime.getRuntime(); Process proc = runtime.exec("vmware"); Is there a way to "daemonize" in Java? ...