fork

Is there a way i can launch another program without having to do a fork()?

Hi, I have a main program written in C, i need it to launch another process in parallel, I used the function system("./server"); the problem is that this process contains a while(1) loop so it never return to the main application... Is there a way i can launch the program without having to do a fork()? thanks! ...

how to exit a child process - _exit() vs. exit

Consider this code snippet: pid_t cpid = fork(); if (cpid == -1) { perror("fork"); exit(EXIT_FAILURE); } if (cpid == 0) { // in child execvp(argv[1], argv + 1); perror("execvp); _exit(EXIT_FAILURE); } // in parent How shall I exit the child process if execvp returns? Shall I use exit() or _exit()? ...

How is stack size of process on linux related to pthread, fork and exec

Hi, guys. I have a question about the stack size of a process on Linux. Is this stack size determined at linkage time and is coded in the ELF file? I wrote a program which print its stack size by pthread_attr_getstacksize(&attr, &stacksize);. And if I run this program directly from shell, it gives a value of about 10MB. But when I exec i...

Why is RLIMIT_STACK lost after fork or exec on linux?

Hello: On linux, it is said that rlimit of a process is kept intact after either fork or exec. But I lose my RLIMIT_STACK in the child either after fork or after exec. Would someone please give some explain? Here is some descriptive output of my program. //The parent has an RLIMIT_STACK like this RLIMIT_STACK, soft - 10485760, hard - ...

create a process tree in C

How would I approach creating a process hierarchy that would look like a balanced ternary tree of depth N? ... meaning each process has 3 children so there would be (3^N-1)/2 processes in a tree of depth N. To create the new processes, I only want to use fork(). This is what I have so far but I don't think it works because I don't deal...

ftp client controlled by pipe in C

Hi! I am trying to control ftp client from C program (OS X). I did fork and execve - process is started ok. The problem is with pipes - I can send command to ftp client process and get feedback from it just fine (If i send "help\n" i get back help output) but what I never get in pipe is "ftp> " prompt. Any ideas? Ivan ...

What are the different ways in which a process can be sent to the background?

I have a big perl script (about 650 lines) that parses data off imdb.com, tvrage.com and can get data using last.fm API, and a few other sites. This script uses quite a few Perl modules so it takes a few seconds to load (on an old PC). What are the different ways (including any 'ugly hacks') in which the script can be sent quickly to the...

php process forking and get the child process id

Hi all, Objective: My script will download a remote file upon form submission, since the file might be big, I would like to fork off a process and let the user go on with his/her life. Example of a command: wget -q --limit-rate=1k --tries=10 "http://helios.gsfc.nasa.gov/image_euv_press.jpg" -O /web/assets/content/image/image_euv_press...

fork() within a fork()

Hi Is there any way to differentiate the child processes created by different fork() functions within a program. global variable i; SIGCHLD handler function() { i--; } handle() { fork() --> FORK2 } main() { while(1) { if(i<5) { i++; if( (fpid=fork())==0) --> FORK1 handle() else (f...

Using Runtime.exec to fork another instance of the current process.

I'm trying to use Runtime.exec to start a copy of the current process. I am not necessarily interested in a fork because I don't need to share state. Is there a way I can determine the command used to start the current process and just re-run this? ...

Behavior of a pipe after a fork()

When reading about pipes in Advanced Programming in the UNIX Environment, I noticed that after a fork that the parent can close() the read end of a pipe and it doesn't close the read end for the child. When a process forks, does its file descriptors get retained? What I mean by this is that before the fork the pipe read file descriptor...

Why does fprintf start printing out of order or not at all?

This code should take an integer, create pipes, spawn two children, wait until they are dead, and start all over again. However, around the third time around the loop I lose my prompt to enter a number and it no longer prints the number I've entered. Any ideas? #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <errno...

Forking in PHP on Windows

We are running PHP on a Windows server (a source of many problems indeed, but migrating is not an option currently). There are a few points where a user-initiated action will need to kick off a few things that take a while and about which the user doesn't need to know if they succeed or fail, such as sending off an email or making sure ...

what is difference between fork and thread

Hi All, Can you any one explain me about what is difference between fork and thread ..? Thanks ...

What's the right way to kill child processes in perl before exiting?

I'm running an IRC Bot (Bot::BasicBot) which has two child processes running File::Tail but when exiting, they don't terminate. So I'm killling them using Proc::ProcessTable like this before exiting: my $parent=$$; my $proc_table=Proc::ProcessTable->new(); for my $proc (@{$proc_table->table()}) { kill(15, $proc->pid) if ($proc->ppid =...

PHP forking and mysql database connection problem

I am now trying to do forking in php. I would like to do some query and update in child process.. the problem is that whenever a child process finish, it close the connection which makes the other queries fail. The following is my sample code!! #!/usr/local/bin/php <?php set_time_limit(0); # forever program! $db = mysql_connect("server"...

forks in C - exercise

I try to repeat and learn more advanced uses and options when cutting trees with forks in the jungle of C. But foolishly I find an example which should be very easy as I have worked with forks before and even written some code, but i can't understand it fully. Here comes : main() { if (fork() == 0) { if (fork() == 0) { printf("3...

Reading a file N lines at a time in ruby

I have a large file (hundreds of megs) that consists of filenames, one per line. I need to loop through the list of filenames, and fork off a process for each filename. I want a maximum of 8 forked processes at a time and I don't want to read the whole filename list into RAM at once. I'm not even sure where to begin, can anyone help me...

How can I manage a fork pool in Perl?

I'm setting something up to SSH out to several servers in 'batches'. I basically want to maintain 5 connections at a time, and when one finishes open up another (following an array of server IPs). I'm wondering for something like this should I be using fork()? If so, what logic can I use to ensure that the I maintain 5 children at a tim...

confusing fork system call

Hi, i was just checking the behaviour of fork system call and i found it very confusing. i saw in a website that Unix will make an exact copy of the parent's address space and give it to the child. Therefore, the parent and child processes have separate address spaces #include <stdio.h> #include <sys/types.h> int main(void) { pid_t ...