Results 1 to 3 of 3
Hi friends,
1. I have created a client socket to receive a data from the server.
2. The data received from the server will be shown in the terminal.
3. ...
- 01-28-2010 #1Just Joined!
- Join Date
- Oct 2008
- Posts
- 30
Socket Error or nohup error ??
Hi friends,
1. I have created a client socket to receive a data from the server.
2. The data received from the server will be shown in the terminal.
3. i want to run this application as a background and i want to redirect the output to a file. and also i want to run this application even when i log out so i did as given below
nohup myprogram > foo.out 2> foo.err < /dev/null &
4. when i use
$tailf foo.out
Everything is fine. I can view the output
but
i cannot able to view the last data i received.
5. If i run that on terminal, everything is fine. i can able to see the data, even the last one i received.
If i run the same using nohup, i could not able to view the last received data.
Can any one help me out to solve this problem

Thanks in advance
- 01-28-2010 #2Linux Guru
- Join Date
- Apr 2009
- Location
- I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
- Posts
- 8,974
The stdout stream is buffered, whereas stderr isn't. This is being exposed by nohup. What you need to do is flush stdout when you write to it in myprogram. If it is a C program, then use "fflush(stdout);". If C++ and you are using cout, then either make sure each output is terminated with the std::endl, std::ends, or std::flush manipulator. An embedded "\n" in C++ sent to std::cout will not flush the buffer, nor will a printf("\n") in C programs.
Sometimes, real fast is almost as good as real time.
Just remember, Semper Gumbi - always be flexible!
- 01-29-2010 #3Just Joined!
- Join Date
- Oct 2008
- Posts
- 30
Thanks for you help. i tried with fflush and sync. But still no improvement.
one thing is that if i run the same on terminal without nohup, it is working fine


Reply With Quote