IPC Review

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

int main() {
    int fh[2];
    pipe(fh);
    FILE *reader = fdopen(fh[0], "r");
    FILE *writer = fdopen(fh[1], "w");
    pid_t p = fork();
    if (p > 0) {
        int score;
        fscanf(reader, "Score %d", &score);
        printf("The child says the score is %d\n", score);
    } else {
        fprintf(writer, "Score %d", 10 + 10);
        fflush(writer);
    }
    return 0;
}
复制代码

If parent want to write and read from child. It need two pipes.

SIGPIPE if no one listening.

If pipe is full and there are no readers, all write will fail until we got new reader. 1.Increase pipe size. 2.Keep read

Pipe is thread safe, kernel will have inner mutex, but if there are

Pipe lifetime: once all procsses closed, pipe will be freed

Named pipe FIFO

- 一、FIFO 在文件系统中做为一个特殊的文件而存在,但 FIFO 中的内容却存放在内存中。

- 二、当使用 FIFO 的进程退出后,FIFO 文件将继续保存在文件系统中以便之后使用。

- 三、FIFO 有名字,不相关的进程能够经过打开命名管道进行通讯。
int mkfifo(const char *pathname, mode_t mode);

FIFO will block直到有read出现(若是Program 1的open是read和write,他不会等reader)
复制代码

若是存在prioritization,会出现饿死的状况

A process will assign to ready queue when it is able to use CPU

turnaround time = end - arrival
response time = start - arrival
wait time = turnaround time - 等菜时间
Convoy Effect 听从 FCFS, 大进程会减慢整个进程的运行速度

复制代码
相关文章
相关标签/搜索