编辑代码

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <signal.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <ctype.h>

void sigusr1_handler(int sig)
{
    printf("Received SIGUSR1 in process %d\n", getpid());
}

void sigusr2_handler(int sig)
{
    printf("Received SIGUSR2 in process %d\n", getpid());
}

int main()
{
    int fd, n;
    char buf;
    signal(SIGUSR1, sigusr1_handler);
    signal(SIGUSR2, sigusr2_handler);
    mkfifo("mypipe", 0666);
    fd = open("mypipe", O_RDONLY);
    while ((n = read(fd, &buf, 1)) > 0) {
        if (isdigit(buf)) {
            printf("N");
        } else if (isalpha(buf)) {
            printf("L");
        } else {
            printf("O");
        }
    }
    close(fd);
    return 0;
}