-
Deamon for Linux!
hi here is my some code for Linux i would like to convert it in Windows but i do not know what s that code do in Linux as i am not programmer for Linux OS. so please any body can describe what that samll piece do or what wil be the output. and PArticulery the daemon(0,0) whts does means by passing ZERO argument to this functions ?
Code:
#include<unistd.h>
..............................
..........................
void echoServerInit(void);
void echoClientInit(void);
int main(int argc, char **argv) {
int startEchoClient = 1;
int startEchoServer = 1;
int daemonize = 0;
int optc;
while ((optc = getopt(argc, argv, "scd")) > 0) {
switch (optc) {
case 's':
startEchoClient = 0;
startEchoServer = 1;
break;
case 'c':
startEchoClient = 1;
startEchoServer = 0;
break;
case 'd':
daemonize = 1;
break;
default:
printf("Invalid option %c\n", optc);
return(-1);
}
}
if (daemonize) {
if (daemon(0, 0) < 0) {
printf("Can't run as daemon: %s\n", strerror(errno));
return(-1);
}
printf("main: running as daemon, pid %d\n", getpid());
}
/* Start up service*/
dctpoInit();
/* Start up the echo server */
if (startEchoServer) {
printf( "main: starting echo-server\n");
echoServerInit();
}
/* Give it time to init */
sleep(3);
/* Start up the echo client */
if (startEchoClient) {
printf( "main: starting echo-client\n");
echoClientInit();
}
/* Let them do their things */
while (1) {
sleep(10);
}
return(0);
}
CHEERS!
-
We have no idea what the daemon() function is supposed to do, because you didn't post it. There is no standard function called daemon(). For that matter, there is no standard function called dcptoInit() or echoServerInit() or echoClientInit() either.
Also, if you are unfamiliar with Linux programming how did you create this code?
-
man daemon
OP: Do you know what a daemon is? The analogue on a Windows machine would be a service.
-
Quote:
Originally Posted by
rags_to_riches
Wow -- shows how much BSD I know...
-
-
Back to the OP: This just looks like a test driver for the DCCP service, with the ability to function as an echo client and/or an echo server (the implementation of which lay outside of the provided driver but appears to be found here).