Need help with fork() on windows


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need help with fork() on windows
# 1  
Old 09-02-2011
Need help with fork() on windows

Here is my sample perl program.
Code:
my $pid = fork();
if(! $pid )
{
      exec("perl sleep.pl 600");
} 
else
{
      print "PID ==== [$pid]\n";
      sleep 30;
      print "killing the PID [$pid] in 20 seconds\n";
      sleep 20;
      kill 9, $pid;
      print "Done ....\n"; 
}

The PID returns the pseudo process ID ( which is a negative number). When kill command sends 9 signal to the pseudo process ID, ( I assume the exec process ID falls under pseudo process ID) the exec process won't get killed.

Any help on how to kill the exec process on windows? I'm running this program on Windows XP.


Thanks In Advance
Hansini

Last edited by Franklin52; 09-02-2011 at 10:51 AM.. Reason: Please use code tags for code and data samples, thank you
# 2  
Old 09-02-2011
Short version:

fork() is creating a new thread within the same process and returning that pseudo-process id. When you exec() from within that pseudo-process' thread, an actual new process with a different pid is created to run the exec()'d executable. The kill() is affecting the pseudo-process thread in the current process, not the separate process created by the exec().

Long version:
See the exec section @ perlfork - perldoc.perl.org

Regards,
Alister

Last edited by alister; 09-02-2011 at 12:58 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

5 More Discussions You Might Find Interesting

1. Programming

Fork!

I understand that fork create a child but I need very simple example that make child useful.... I mean how will make the program faster anyone explain with code plz using C plz (2 Replies)
Discussion started by: fwrlfo
2 Replies

2. UNIX for Dummies Questions & Answers

fork()

I'm trying to run a simple test on how to use fork(), i'm able to execute the child process first then the parent, but how can I execute parent then child..? Thanks! (1 Reply)
Discussion started by: l flipboi l
1 Replies

3. Programming

Fork and \n

Hi, I wrote a simple program for understanding the fork command. The code is as below int main(void) { fork(); printf("hi 1 \n"); fork(); printf("hi 2 \n"); fork(); printf("hi 3 \n"); } I am getting a variation in the number of times the printf is called if i remove the \n from each... (2 Replies)
Discussion started by: xyz123456
2 Replies

4. Programming

Fork or what?

Hello all. I'm developing a filetransfer application, which is supposed to work sort of like dcc, with multiple transfers etc. Now i wonder what the best way to manage the transfers is. Should i fork() for each new transfer, hogging loads of memory or use pthreads? Maybe I can use select to see... (0 Replies)
Discussion started by: crippe
0 Replies

5. Programming

how to use function fork() in Windows NT

Hello, I need to make a gateway from Ethernet to RS-485. I am using stream socket, and I am programming in windows nt. I would like to know how could I use some functions from unix in windows nt. I would like to use the function fork(). Which library it uses and how can I get it? Can I... (1 Reply)
Discussion started by: danieljorge
1 Replies
Login or Register to Ask a Question