Linux管道实验题

Linux管道实验题,第1张

<pre t="code" l="cpp">#include <unistd.h>

#include <stdio.h>

//警告: 该程序未做错误验证, 未关闭管道(由系统自动关闭)

int main()

{

int p2c[2]// 该管道父进程写,子进程读

int c2p[2]// 该管道子进程写,父进程读

// 创建2条管道

pipe(p2c)

pipe(c2p)

int pid = fork()

int fd_read, fd_write// 这两个描述符用于保存某进程读端和写端

int pid_my// 保存某进程自身的pid

int pid_other// 另一进程的pid,通过

if ( pid == 0 ) { // 子进程

fd_read = p2c[0]

fd_write= c2p[1]

// 通过getpid取得自身pid,写到管道里

pid_my = getpid()

write(fd_write, pid_my, sizeof(int))

// 从另一管道读取另一进程的pid

read(fd_read, pid_other, sizeof(int))

// 打印读取到的pid

printf("Recive pid : %d\n", pid_other)

} else { // p

fd_read = c2p[0]

fd_write= p2c[1]

pid_my = getpid()

// 由于子进程是先写自身pid,父进程最好先读取子进程的pid

read(fd_read, pid_other, sizeof(int))

write(fd_write, pid_my, sizeof(int))

printf("Recive pid : %d\n", pid_other)

}

return 0

}

quota是针对一般用户或群组设定的,也可以针对文件系统。

设置用户的磁盘限额:edquota -u username

Filesystem    blocks    soft    hard  inodes  soft  hard

  /dev/hdaN        xxx    2048  3000   xx    0     0

单位是KB

mv /a1/* /c1

mv /c1/d2/k /c1/c2/j /b1

mv /c1/c2/i /b1/f /a1

rm -rf /c1/*2


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/7273761.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-03
下一篇 2023-04-03

发表评论

登录后才能评论

评论列表(0条)

保存