-
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);
}*/
}
}
-
Re: printf and server
puntino <domenico.dileo@gmail.com> wrote:[color=blue]
> 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[/color]
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
[email]jfdsmit@few.vu.nl[/email] | [url]http://www.few.vu.nl/~jfdsmit[/url]
"[In the end, people] get furious at IT that the goddamn magic isn't working"
-- Stewart Dean
-
Re: printf and server
On Jun 23, 8:41 am, "J.F. de Smit" <jst...@keg.few.vu.nl> wrote:[color=blue]
> puntino <domenico.di...@gmail.com> wrote:[color=green]
> > 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[/color]
>
> 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 |[url]http://www.few.vu.nl/~jfdsmit[/url]
> "[In the end, people] get furious at IT that the goddamn magic isn't working"
> -- Stewart Dean[/color]
Can I change the std output only for my server ? I need to see my
instrunctions on the monitor
How ?
Thank you in advance
-
Re: printf and server
On 2008-06-23, puntino <domenico.dileo@gmail.com> expressed:[color=blue]
> On Jun 23, 8:41 am, "J.F. de Smit" <jst...@keg.few.vu.nl> wrote:[color=green]
>>
>> 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.[/color]
>
> Can I change the std output only for my server ? I need to see my
> instrunctions on the monitor
> How ?[/color]
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.
[color=blue]
> Thank you in advance[/color]
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
-
Re: printf and server
Since I'm not pretty use to Unix system,
please could you give me an example for:
[color=blue]
> The standard is to send all logging to a file. You can follow it with
> tail -f.[/color]
and
[color=blue]
> 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.[/color]
Thank you
-
Re: printf and server
On 2008-07-03, puntino <domenico.dileo@gmail.com> expressed:[color=blue]
>
> Since I'm not pretty use to Unix system,
> please could you give me an example for:
>
>[color=green]
>> The standard is to send all logging to a file. You can follow it with
>> tail -f.[/color]
>
> and[/color]
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).
[color=blue][color=green]
>> 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.[/color]
>[/color]
The simplest method:
#include <unistd.h>
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