i got problem with stdin and sigquit signal handling. The task is to ignore sigquit signal. Everything is fine, except all 'read' buffer is gone, and i don't know how to avoid it . Here's my code:
#include <unistd.h>
#include <signal.h>
#include <sys/types.h>
#include <strings.h>
int main(void)
{
char buffer[4096];
int byte;
bzero(buffer, 4096);
signal(SIGQUIT, SIG_IGN);
while ((byte = read(0, &buffer, 4096)))
{
if (strlen(buffer) == 5 && !strncmp(buffer, "exit", 4))
break ;
write(1, "STDOUT | ", strlen("STDOUT | "));
write(1, buffer, strlen(buffer));
bzero(buffer, 4096);
}
write(1, "Program is finished\n", strlen("Program is finished\n"));
return (0);
}
Here's my output:
$ ./test
hello world
STDOUT | hello world
hello world^\
STDOUT |
The way it should be
STDOUT | The way it should be
And how it is now^\
STDOUT |
i need help
STDOUT | i need help
really^\
STDOUT |
exit
Program is finished
OS: MacOS Mojave - 10.14.6 Clang verison: 11.0.1