printf and server - Minix

This is a discussion on printf and server - Minix ; I've written a simple server whose goal is to do some math operations (e.g. average) and print the result on the stdout (I use "printf"). To make this server run I use the command "service up /myfolder/myserver" but i can't ...

+ Reply to Thread
Results 1 to 6 of 6

Thread: printf and server

  1. printf and server

    I've written a simple server whose goal is to do
    some math operations (e.g. average) and print
    the result on the stdout (I use "printf").
    To make this server run I use the command
    "service up /myfolder/myserver"
    but i can't see any printf on the std output, why ??
    For example I' d like to see the string "I'm working" in the
    following code
    Thank you

    this the code:
    I


    while(TRUE){

    get_work(&m);
    who_e = m.m_source;
    printf("I'm working");
    /*ES receives two types of messages: ping from RS and
    request for elaboration from client(s) */

    switch(m.m_type){
    case DEV_PING: notify(who_e);
    #ifdef VERBOSE
    printf("Reply to RS \n");
    #endif
    continue; /*reply to RS'ping */
    case ES_REQ: result = do_elaboration(&m); break;
    default:
    printf("Warning, ES doesn't support message type %d from %d \n",
    m.m_type, m.m_source);
    result = EINVAL;
    }
    /*
    if (result != EDONTREPLY){ /* ES should always send a message
    reply(who_e,result);

    }*/
    }
    }

  2. Re: printf and server

    puntino wrote:
    > I've written a simple server whose goal is to do
    > some math operations (e.g. average) and print
    > the result on the stdout (I use "printf").
    > To make this server run I use the command
    > "service up /myfolder/myserver"
    > but i can't see any printf on the std output, why ??
    > For example I' d like to see the string "I'm working" in the
    > following code


    Servers have the console as standard output, not the terminal from where
    it was launched. In standard setups, tty0 is the console, so you'll have
    to monitor that one to see your print statements.

    Regards,

    Jens

    --
    Jens de Smit
    Student Computer Science | Vrije Universiteit Amsterdam
    jfdsmit@few.vu.nl | http://www.few.vu.nl/~jfdsmit
    "[In the end, people] get furious at IT that the goddamn magic isn't working"
    -- Stewart Dean

  3. Re: printf and server

    On Jun 23, 8:41 am, "J.F. de Smit" wrote:
    > puntino wrote:
    > > I've written a simple server whose goal is to do
    > > some math operations (e.g. average) and print
    > > the result on the stdout (I use "printf").
    > > To make this server run I use the command
    > > "service up /myfolder/myserver"
    > > but i can't see any printf on the std output, why ??
    > > For example I' d like to see the string "I'm working" in the
    > > following code

    >
    > Servers have the console as standard output, not the terminal from where
    > it was launched. In standard setups, tty0 is the console, so you'll have
    > to monitor that one to see your print statements.
    >
    > Regards,
    >
    > Jens
    >
    > --
    > Jens de Smit
    > Student Computer Science | Vrije Universiteit Amsterdam
    > jfds...@few.vu.nl |http://www.few.vu.nl/~jfdsmit
    > "[In the end, people] get furious at IT that the goddamn magic isn't working"
    > -- Stewart Dean



    Can I change the std output only for my server ? I need to see my
    instrunctions on the monitor
    How ?
    Thank you in advance

  4. Re: printf and server

    On 2008-06-23, puntino expressed:
    > On Jun 23, 8:41 am, "J.F. de Smit" wrote:
    >>
    >> Servers have the console as standard output, not the terminal from where
    >> it was launched. In standard setups, tty0 is the console, so you'll have
    >> to monitor that one to see your print statements.

    >
    > Can I change the std output only for my server ? I need to see my
    > instrunctions on the monitor
    > How ?

    The standard is to send all logging to a file. You can follow it with
    tail -f.

    If you don't want to change all your printf into fprintf, you should
    close stdout (fileno 1), and reopen it.

    The standard method is to open a file (for writing). If all goes well,
    close stdout (fileno 1). And then use dup(include "unistd.h") to duplicate the
    fileno to fileno 1.

    > Thank you in advance


    Hope it helps (If you really want the logging to your terminal, try
    writing it to /dev/tty, or what else the tty-command tells you)

    Greetings,
    Frank

  5. Re: printf and server


    Since I'm not pretty use to Unix system,
    please could you give me an example for:


    > The standard is to send all logging to a file. You can follow it with
    > tail -f.


    and

    > The standard method is to open a file (for writing). If all goes well,
    > close stdout (fileno 1). And then use dup(include "unistd.h") to duplicate the
    > fileno to fileno 1.



    Thank you

  6. Re: printf and server

    On 2008-07-03, puntino expressed:
    >
    > Since I'm not pretty use to Unix system,
    > please could you give me an example for:
    >
    >
    >> The standard is to send all logging to a file. You can follow it with
    >> tail -f.

    >
    > and


    Say you are logging to file "x.log". In that case you can watch your
    logging (quasi-)online by the command "tail -f x.log" (read man tail).

    >> The standard method is to open a file (for writing). If all goes well,
    >> close stdout (fileno 1). And then use dup(include "unistd.h") to duplicate the
    >> fileno to fileno 1.

    >


    The simplest method:

    #include

    void redirect()
    {
    int f_id;
    /* open the log-file */
    f_id = open("mylog.log", O_CREAT|O_WRONLF|O_TRUNC);
    /* Panic if f_id == -1 !!! (not shown here) */
    /* close stdout */
    close(STDOUT_FILENO);
    /* stdout is the lowest free file-id, so it will be reused */
    dup(f_id);
    }

    This way it is impossible to tell the people you couldn't redirect,
    because you closed stdout.

    For real debugging the next option is nice:

    #define LOG(x) fprintf( log, "%s(%d):%s\n", __FILENAME__, __LINENO__, x
    )


    main()
    {
    log=fopen( "logfile" ,"w" );
    LOG("Dit is een test");
    }

    (excuse me ik I made some programming mistakes)

    Greetings,
    Frank

+ Reply to Thread