nonblocking.c

it opens a pseudo-terminal(/dev/pts/2) in non-blocking, write-only mode and then attempt to write data continuously into the pipe

#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main() {
    int fd;
    char *device = "/dev/pts/2";

    fd = open(device, O_WRONLY | O_NONBLOCK);
    if (fd < 0) {
        perror("open");
        exit(1);
    }

    // Try writing a large buffer to fill the buffer
    char buffer[1024];  // smaller buffer for repeated writes
    memset(buffer, 'A', sizeof(buffer));
    ssize_t ret;

    while (1) {
        ret = write(fd, buffer, sizeof(buffer));
    }
    close(fd);
    return 0;
}