Linux概述:
历史:无系统→单任务、单用户系统(DOS)→多任务、多用户系统(Windows、UNIX),UNIX是Linux的老祖宗,minix是他的爹
应用:个人桌面、服务器、嵌入式系统
Ubuntu:samba:Windows和Linux通信,Windows访问Linux共享文件目录
ssh:远程登录的一种协议
环境开发:文件及目录结构(Linux内心)、Linux命令、编辑器(gedit)、编译器(gcc)、调试器(gdb)、shell(处理多Linux命令执行逻辑,多个cd啊,cp啥的命令)、makefile(处理多文件编译逻辑,多个.c)
(1)Linux常用指令的用法
(2)库函数
(3)Linux文件类型
(4)shell变量的用法,相关符号的使用
(5)进程状态、类型及概念
(6)Makefile相关符号
(7)常用信号
(8)消息队列的操作
(9)管道的操作
(10)文件描述符
(11)无名管道及命名管道
编程题:
(12)文件内容复制的编程操作
打开一个文件open通过文件指针读read出来,再通过write写进去。
#include<stdio.h>
#include<sys/types.h> // 定义新的数据类型
#include<sys/stat.h> // 文件信息结构体的定义
#include<fcntl.h> // 声明系统调用
#include<unistd.h>
#include<stdlib.h>
int main(int argc, char *argv[])
{
int fd,fd_new,length;
char *buf;
fd = open("/home/wei/1.txt",O_RDONLY);
if(fd<0)
{
perror("error");
return -1;
}
// open(路径,行为标志,权限设定) O_RDWR|O_CREAT 可读可写文件不存在就创建 返回文件描述符
fd_new = open("/home/wei/2.txt",O_RDWR|O_CREAT,0755);
if(fd_new<0)
{
close(fd);
perror("error");
return -1;
}
lseek(fd,0,SEEK_SET);
length = lseek(fd,0,SEEK_END);
buf = (char *)malloc(length+1);
lseek(fd,0,SEEK_SET); // 文件指针搞回来
read(fd,buf,length);
write(fd_new,buf,length);
close(fd);
close(fd_new);
return 0;
}
(13)消息队列的发送和接收编程操作
接受操作:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/msg.h>
#define KEY = 1000
struct msg{的
long mtype; //消息队列类型必须是long且作为开头
char mtext[256]; //消息正文
};
int main(){
int msgid;
struct msg msgtxt;
msgid = msgget((key_t)KEY,IPC_CREATE|0666); //key也可以ftok,IPC_CREATE不存在就创建
if(msgid == -1){
perror("error");
exit(-1);
}
// msgrcv(消息队列ID,存放消息结构体的地址,消息正文字节数,消息类型,函数控制属性)
// 其中消息类型为>0,返回消息类型为msgtyp的消息,=0返回第一个消息,<0返回队列中消息类型值小于或等于
// msgtyp绝对值的消息,如果这种消息有若干个,则取类型值最小的消息
// 函数控制属性:0代表msgrcv阻塞到接受消息成功为止,IPC_NOWAIT立即返回,
// MSG_NOERROR若返回的消息字节数比nbytes字节数多,则消息就会截短到nbytes字节,且不通知消息发送进程。
msgrcv(msgid,&msgtxt,sizeof(msgtxt.mtext),6,0)
printf("%s\\n",msgtxt.mtext);
msgctl(msgid,IPC_RMID,NULL);
return 0;
}