下载此文档

linux复习资料.docx


文档分类:IT计算机 | 页数:约24页 举报非法文档有奖
1/24
下载提示
  • 1.该资料是网友上传的,本站提供全文预览,预览什么样,下载就什么样。
  • 2.下载该文档所得收入归上传者、原创者。
  • 3.下载的文档,不会出现我们的网址水印。
1/24 下载此文档
文档列表 文档介绍
第 1 页
1、指令格式:
指令名称 [选择项] [参数列表]
选择项以-开头
通配符
* :代表文件名中任意长度字符串;
?:代表文件名中任一字符
[] :代表文件名中任一属于字符组中字符
2、
3 gcc根本么产生SIGPIPE信号。如果忽略该信号或者捕捉该信号并处理程序返回,那么write返回-1,errno设置为EPIPE
第 4 页
父子进程通过无名管道通信
else {
close(pipe_fd[0]);
printf("please input the string:");
scanf("%s",buf_w);
if(write(pipe_fd[1],buf_w,strlen(buf_w))!=-1)
printf("parent process has written:%s to the pipe!\n",buf_w);
close(pipe_fd[1]);
waitpid(result,NULL,0);
exit(0); }}
#include <>
#include <>
#include <sys/>
#include <sys/>
#include <>
#include <>
main(){
pid_t result;
int r_num;
int pipe_fd[2];
char buf_r[100],buf_w[100]; memset(buf_r,0,sizeof(buf_r));
if(pipe(pipe_fd)<0) {
perror("pipe");
exit(EXIT_FAILURE); }
result=fork();
if(result<0) {
perror("fork");
exit(EXIT_FAILURE); }
else if(result==0) {
close(pipe_fd[1]);
if((r_num=read(pipe_fd[0],buf_r,100))>0)
printf("child process has read %d characters from the pipe,the string is:%s\n",r_num,buf_r);
close(pipe_fd[0]);
exit(0); }
信号是Linux系统中用于进程之间相互通信或操作的一种机制。
信号事件的发生有两个来源:
1. 硬件来源:用户按某些终端键时将产生信号,如CTRL+C将产生SIGINT〔中止信号〕;硬件异常产生信号,如除数为0或无效的存储访问等。
2. 软件来源:终止进程信号,其他进程调用kill函数,将信号发送个另一个进程或进程组;软件异常产生信号。
信号处理
信号注销
信号注册
内核进程
用户进程
信号产生
*
生命周期
〔3〕设计一个程序,要求翻开文件“pass〞,如果没有这个文件,新建此文件;读取系统文件“/etc/passwd〞,把文件中内容都写入“pass〞文件。
#include <>#include <>
#include <>#include <>
#include <sys/>
int main(int agrs,char *args[])
{int fd_src,fd_des,num;char buf[10];
if((fd_des=open("pass",O_CREAT|O_WRONLY|O_TRUNC,0644))<0)
{ perror("open or create \n");
exit(EXIT_FAILURE);}
第 5 页
if((fd_src=open("/etc/passwd",O_RDONLY,0644))==-1)
{perror("open passwd \n");
exit(EXIT_FAILURE); }
do{ num =read(fd_src,buf,10);
write(fd_des,buf,num);}
while(num >= 10);close(fd_src); close(fd_des);
return 0;}
〔4〕设计一个程序,要求新建一个目录,预设权限为d--x--x--x。
#include<> #include<

linux复习资料 来自淘豆网m.daumloan.com转载请标明出处.

相关文档 更多>>
非法内容举报中心
文档信息
  • 页数24
  • 收藏数0 收藏
  • 顶次数0
  • 上传人2623466021
  • 文件大小35 KB
  • 时间2022-04-20
最近更新