Thread: Deamon for Linux!

  1. #1
    Registered User
    Join Date
    May 2008
    Posts
    1

    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!

  2. #2
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    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?

  3. #3
    Registered User
    Join Date
    Dec 2007
    Posts
    2,675
    man daemon

    OP: Do you know what a daemon is? The analogue on a Windows machine would be a service.

  4. #4
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by rags_to_riches View Post
    Wow -- shows how much BSD I know...

  5. #5
    Registered User
    Join Date
    Dec 2007
    Posts
    2,675
    Looks like he's trying to port a DCCP stack to Windows.

  6. #6
    Registered User
    Join Date
    Dec 2007
    Posts
    2,675
    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).

Popular pages Recent additions subscribe to a feed