发发发VV

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <ctype.h>

#define BUFFER_SIZE 100

int main() {
    int pipefd[2];
    pid_t pid;

    if (pipe(pipefd) == -1) {
        perror("pipe");
        exit(EXIT_FAILURE);
    }

    pid = fork();

    if (pid < 0) {
        perror("fork");
        exit(EXIT_FAILURE);
    }

    if (pid > 0) {  // parent process
        close(pipefd[0]);  // close the read end of the pipe

        char message[] = "Hello, this is a message from the parent process.";
        printf("Parent process sending message: %s\n", message);

        write(pipefd[1], message, strlen(message) + 1);

        close(pipefd[1]);  // close the write end of the pipe

    } else {  // child process
        close(pipefd[1]);  // close the write end of the pipe

        char received_message[BUFFER_SIZE];
        read(pipefd[0], received_message, BUFFER_SIZE);

        printf("Child process received message: %s\n", received_message);

        for (int i = 0; received_message[i]; i++) {
            if (islower(received_message[i])) {
                received_message[i] = toupper(received_message[i]);
            } else if (isupper(received_message[i])) {
                received_message[i] = tolower(received_message[i]);
            }
        }

        printf("Child process changing case: %s\n", received_message);

        close(pipefd[0]);  // close the read end of the pipe
        write(pipefd[1], received_message, strlen(received_message) + 1);
    }

    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值