Deamon for Linux!

This is a discussion on Deamon for Linux! within the Linux Programming forums, part of the Platform Specific Boards category; hi here is my some code for Linux i would like to convert it in Windows but i do not ...

  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
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,243
    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
    a_capitalist_story
    Join Date
    Dec 2007
    Posts
    2,651
    man daemon

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

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

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

  6. #6
    a_capitalist_story
    Join Date
    Dec 2007
    Posts
    2,651
    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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21