471,319 Members | 1,307 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,319 software developers and data experts.

can we do fork() in c#

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

Nov 30 '05 #1
4 14827
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

Nov 30 '05 #2
lucifer wrote:
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
--
------------------------------------------------------------------------
Get LLBLGen Pro, productive O/R mapping for .NET: http://www.llblgen.com
My .NET blog: http://weblogs.asp.net/fbouma
Microsoft MVP (C#)
------------------------------------------------------------------------
Dec 1 '05 #3
i am asking how some example as i dont know how

Dec 1 '05 #4
lucifer wrote:
i am asking how some example as i dont know how


See http://www.pobox.com/~skeet/csharp/threads

Jon

Dec 1 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Benoit Dejean | last post: by
6 posts views Thread by shellcode | last post: by
27 posts views Thread by steve | last post: by
11 posts views Thread by ramu | last post: by
1 post views Thread by vduber6er | last post: by
3 posts views Thread by thrillseekersforever | last post: by
5 posts views Thread by JoeW | last post: by
3 posts views Thread by CMorgan | last post: by
9 posts views Thread by Gilles Ganault | last post: by
2 posts views Thread by Radz | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.