I have a C file that looks like this:
#include <stdio.h>
int main(void)
{
printf("Hello world\n");
while (1);
return 0;
}
And I would like to see "Hello world" printed in a new file. But it doesn't work when I try to redirect the standard output like this:
./hello_world >> logfile &
And then kill the program hello_world.
You need to flush stdout before the loop:
#include <stdio.h>
int main(void)
{
printf("Hello world\n");
fflush(stdout);
while (1);
return 0;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With