désolé mais je vais arrêter là les discussions, car je trouve ce comportement très logique, ça s'appelle la mise en cache et si tu la veux pas on te donne l'api pour la désactiver.
ce que tu veux n'est pas standard, flemme d'expliquer pourquoi a base d'arguments historiques sur les TTY et/ou les performances.
je vois pour info
man setbuf a dit:
Normally, all files are block buffered. When the first I/O operation
occurs on a file, malloc(3) is called and an optimally-sized buffer is
obtained. If a stream refers to a terminal (as stdout normally does), it
is line buffered. The standard error stream stderr is always unbuffered.
mais il faut savoir ou chercher.
faut pas abuser, c'est quand même simple ,
soit tu fais printf("blabla\n")
soit tu fais printf(blabla) plus fflush(stdout)
soit tu fais setvbuf(stdout, NULL, _IONBF, 0); avant le reste
et si tu veux toujours pas céder ou pas réécrire ton code tu fais un LD_PRELOAD
#include <dlfcn.h>
#include <stdio.h>
#include <stdarg.h>
static void * libc=NULL;
typedef int (*vprintf_t)(const char *, va_list);
static vprintf_t oldvprintf=NULL;
int printf(const char *fmt, ...) {
va_list ap;
int retval;
va_start(fmt,ap);
if(libc==NULL) libc=dlopen("/lib/libc.so.6",RTLD_LAZY);
if(libc==NULL) exit(1);
oldvprintf=dlsym(libc, "vprintf");
if(oldvprintf==null) exit(1);
retval=oldvprintf(fmt, ap);
va_end(ap);
fflush(stdout);
return retval;
}
(écrit à la main, a arranger sans doute)
intf(fmt, ap);
va_end(ap);
return retval;
}
ou encore (même pas la peine de faire du dlmachin) #include <stdio.h>
#include <stdarg.h>
static int firstcall=1;
int printf(const char *fmt, ...)
{
va_list ap;
int retval;
va_start(fmt,ap);
if(!firstcall)
{
setvbuf(stdout,NULL,_IONBF,0);
firstcall=0;
}
retval=vpr
tval;
}
ou même#include <stdio.h>
#include <stdarg.h>
int printf(const char *fmt, ...)
{
va_list ap;
int retval;
va_start(fmt,ap);
retval=vprintf(fmt, ap);
va_end(ap);
fflush(stdout);
return re
(écrit à la main, a arranger sans doute)
gcc -shared -fPIC flushprintf.c -o flusprintf.so
LD_PRELOAD=./flushprintf.so ./mefepluchier
si tu veux que ça reste tu peux en faire une variable d'env dans ton .bashrc