小编AAA*_*AAA的帖子

直接使用系统调用

我对操作系统中的系统调用有很大的困惑。根据《操作系统概念第 9 版》一书,(第 63 页)提到:

然而,大多数程序员从未见过这种程度的细节。通常,应用程序开发人员根据应用程序编程接口(API)来设计程序。

在幕后,构成 API 的函数通常代表应用程序程序员调用实际的系统调用。

这意味着,作为程序员,我们不直接使用系统调用。但是,我看到教如何直接使用系统调用的视频,例如这个视频,它访问 read|() 和 write() 系统调用。所以系统调用可以直接使用,也可以使用 API,或者两者都使用??

system-calls

7
推荐指数
3
解决办法
3558
查看次数

封闭管道的不同端部

我使用以下命令为 IPC 编写了以下代码pipe():

#include <unistd.h>
#include <stdio.h>
#include <sys/wait.h>
    
    
int main(void) {
    char message_buffer[15] = "Hello World \n";  
    char read_buffer[15];
    int fd[2]; 
   
    int return_value = pipe(fd);
   
    if (return_value < 0) {
        printf("Error creating the pipe");
    }
    
    int rc = fork();
    if (rc  < 0) {
        printf("Error forking a child");
    }
    
    if (rc > 0) {
        close(fd[0]);
        write(fd[1], message_buffer, 15);
        close(fd[1]);
        wait(NULL);
    } else {
        close(fd[1]);
        read(fd[0], read_buffer, 15);
        close(fd[0]);
        printf("The Message: %s", read_buffer);
    }

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

我是管道新手,我有以下问题: …

linux c pipe

2
推荐指数
1
解决办法
8086
查看次数

标签 统计

c ×1

linux ×1

pipe ×1

system-calls ×1