fork

Controlling Forks in C

I have a c file that looks like this: #include <stdio.h> #include <sys/types.h> #include <unistd.h> int main () { pid_t child_pid; printf ("The PID is %d\n", (int) getpid ()); child_pid = fork (); if (child_pid != 0) { printf ("this is the parent process, with PID %d\n", (int)getpid()); prin...

About fork system call and global variables

I have this program in C++ that forks two new processes: #include <pthread.h> #include <iostream> #include <unistd.h> #include <sys/types.h> #include <sys/wait.h> #include <cstdlib> using namespace std; int shared; void func(){ extern int shared; for (int i=0; i<10;i++) shared++; cout<<"Process "<<getpid()<<", shared " ...

How can I signal a forked child to terminate in Perl?

How can I make the same variable shared between the forked process? Or do I need to write to a file in the parent then read the value saved to the file in the child once the file exists? $something never appears to get set in this so it just loops in the sleep my $something = -1; &doit(); sub doit { my $pid = fork(); if ($pid == 0) ...

cat/Xargs/command VS for/bash/command

The page 38 of the book Linux 101 Hacks suggests: cat url-list.txt | xargs wget –c I usually do: for i in `cat url-list.txt` do wget -c $i done Is there some thing, other than length, where the xargs-technique is superior to the old good for-loop-technique in bash? Added The C source code seems to have only one fork. ...

Merging a Trunk into a Forked Branch

Hopefully this makes sense: In subversion if I branch a trunk and then fork the branch can I merge changes from the trunk into the forked branch? ...

How do I speed up my Ruby application?

I am making a data intensive web application that I am trying to optimize. I've heard of forking and threading, but I have no idea whether they are applicable to what I am trying to do and if so how to implement them. My code looks like this: def search @amazon_data=Hash.from_xml(item.retrieve_amazon(params[:sku])) unles...

How to lock IO shared by fork in ruby

How can we lock an IO that has been shared by multiple ruby process? Consider this script: #!/usr/bin/ruby -w # vim: ts=2 sw=2 et if ARGV.length != 2 $stderr.puts "Usage: test-io-fork.rb num_child num_iteration" exit 1 end CHILD = ARGV[0].to_i ITERATION = ARGV[1].to_i def now t = Time.now "#{t.strftime('%H:%M:%S')}.#{t.usec}" ...

Applications of fork system call

fork is used to create a copy of process from which its called. This is typically followed by calls to exec family of functions. Are there any usages of fork other than this? I can think of one. Doing IPC with pipe functions. ...

Fork MySQL INSERT INTO (InnoDB)

Hello, I'm trying to insert about 500 million rows of garbage data into a database for testing. Right now I have a PHP script looping through a few SELECT/INSERT statements each inside a TRANSACTION -- clearly this isn't the best solution. The tables are InnoDB (row-level locking). I'm wondering if I (properly) fork the process, will ...

Problem with polling sockets in python.

After I begin the polling loop, all messages printed after the first iteration require me to press enter in the terminal for it to be displayed. #!/usr/bin/python import socket, select, os, pty, sys s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.bind(('', 5007)) s.listen(5) mypoll = select.poll() mypoll.register(s.fileno() ) ...

running process in backround using a bash script

I want run a script as follows: runner: ssh 'java program &' ssh 'java program &' How do I write the script to fork the first process? Currently, it waits for it to finish. thanks ...

Create an executable process without using shell on Python 2.5 and below

Just what the title says: The subprocess module cannot be used as this should work on 2.4 and 2.5 Shell process should not be spawned to pass arguments. To explain (2), consider the following code: >>> x=os.system('foo arg') sh: foo: not found >>> x=os.popen('foo arg') sh: foo: not found >>> As you can see os.system and os.popen r...

In Django, how to call a subprocess with a slow start-up time.

Suppose you're running Django on Linux, and you've got a view, and you want that view to return the data from a subprocess called cmd that operates on a file that the view creates, for example likeso: def call_subprocess(request): response = HttpResponse() with tempfile.NamedTemporaryFile("W") as f: f.write(request....

How do I fork a new process and get back its PID in Perl?

My issue is related to using fork() within Perl code. I wish to fork a new process and capture its PID and return it back to the callee program. Is there some command in Perl which would make this possible? ...

running function pauses parent function

hey there, just practising and I had a question. I have a program (source below) that prints out a wave in text. when the wave hits the outside of the terminal I have it make a noise with a function called noise(). but when that function is called it pauses the animation until it completes making the noise, then the animation starts agai...

Forking / Multi-Threaded Processes | Bash

Hi all - I would like to make a section of my code more efficient. I'm thinking of making it fork off into multiple processes and have them execute 50/100 times at once, instead of just once. For example (pseudo): for line in file; do foo; foo2; foo3; done I would like this for loop to run multiple times. I know this can be done w...

Why does ant.bat not return an error status when run programmatically?

When I run ant from the command-line, if I get a failure, I get a non-zero exit status ($? on UNIX, %ERRORLEVEL% on Windows). But we have a Java program which is running ant (through ProcessBuilder), and when ant fails, on Windows we cannot get the exit status. I just verified this with this simple ant test file: <project name="x" def...

Fork Arbitrary Amount of Children from a Parent in C?

I have found examples of how to fork multiple children by having something like this: if ( fork() = 0 ) { //In child } else { if ( fork() = 0 ) { //in second child But if I don't know how many children I am going to need, how might I do this? For instance, if I have a linked list of commands, and I want to fork and exe...

PHP mysqli reconnect problem

I am having trouble using the mysqli class in PHP and I haven't been able to find the answer anywhere. In my script a class creates a mysqli connection that it uses throughout it's functions. Afterward, this script forks. The connection is used by the children as well, but I'm running into the problem of the connection being closed (MYS...

Why does my antivirus program not detect this malicious behavior?

I wrote this C program and ran on my Windows system. My system hanged and not even Task manager was opening. Finally, I had to reboot. This is clearly a malicious program, but my antivirus does not detect this. Why? #include<unistd.h> main() { while(1) fork(); } ...