can we do fork() in c#

  • Thread starter Thread starter lucifer
  • Start date Start date
L

lucifer

hi
i have code that i have to implement in c#

Code:

/* Become deamon + unstopable and no zombies children
(= no wait()) */
if(fork() != 0)
return 0; /* parent returns OK to shell */
(void)signal(SIGCLD, SIG_IGN); /* ignore child death */
(void)signal(SIGHUP, SIG_IGN); /* ignore terminal hangups */
for(i=0;i<32;i++)
(void)close(i); /* close open files */
(void)setpgrp(); /* break away from process group
*/


if((pid = fork()) < 0) {
log(ERROR,"system call","fork",0);
}
else {
if(pid == 0) { /* child */
(void)close(listenfd);
web(socketfd,hit); /* never returns */
} else { /* parent */
(void)close(socketfd);
}
}
}


i know the code is creating child process mine question is can we do
fork in c# or is there any other method to do so eg threading etc
 
I don't think you need to fork at all. The C code you posted only uses
fork() to become a daemon, that is, a background process. That's so you
can start the program at the Unix prompt and have it immediately return
to the prompt, even though the daemon keeps running.

In Windows, you can just start a program and let it run in the
background with no extra work needed. Even from the command prompt, if
you type "notepad", you immediately get another prompt.

Jesse
 
lucifer said:
hi
i have code that i have to implement in c#

Code:

/* Become deamon + unstopable and no zombies children
(= no wait()) */
if(fork() != 0)
return 0; /* parent returns OK to shell */
(void)signal(SIGCLD, SIG_IGN); /* ignore child death */
(void)signal(SIGHUP, SIG_IGN); /* ignore terminal hangups */
for(i=0;i<32;i++)
(void)close(i); /* close open files */
(void)setpgrp(); /* break away from process group
*/


if((pid = fork()) < 0) {
log(ERROR,"system call","fork",0);
}
else {
if(pid == 0) { /* child */
(void)close(listenfd);
web(socketfd,hit); /* never returns */
} else { /* parent */
(void)close(socketfd);
}
}
}


i know the code is creating child process mine question is can we do
fork in c# or is there any other method to do so eg threading etc

You can mimic fork, which simply spawns another thread at the same
position, by using threads indeed. Simply start a thread which actually
runs your program and let the main thread return.

FB


--
 
Back
Top