Akuli / porcupine

A decent editor written in tkinter
MIT License
148 stars 47 forks source link

c stdio buffering #973

Open Akuli opened 2 years ago

Akuli commented 2 years ago
#define _XOPEN_SOURCE 500
#include <stdio.h>
#include <unistd.h>

int main(void)
{
    while(1) {
        printf("a\n");
        fflush(stdout);
        usleep(500000);
    }
}

Try compiling and running this in porcupine. Doesn't print anything if you remove fflush(stdout)

Akuli commented 2 years ago

stdbuf might be good for this

akuli@akuli-desktop:~$ cat foo.c
#include <stdio.h>
#include <sys/select.h>

int main(void)
{
    printf("a\n");

    struct timeval t = { .tv_sec = 1 };
    select(0, (fd_set *)0, (fd_set *)0, (fd_set *)0, &t);

    printf("b\n");
}
akuli@akuli-desktop:~$ gcc foo.c
akuli@akuli-desktop:~$ timeout 1 ./a.out | cat
Terminated
akuli@akuli-desktop:~$ timeout 1 stdbuf -o0 ./a.out | cat
a
Terminated