Live Note

Remain optimistic

要求

父进程创建 3 个进程,父进程等待子进程 2 运行完成之后,自行退出;其中子进程 1 运行系统命令“cp /bin/ls /tmp”;等待 2 秒后退出;子进程 2 使用标准 I/O 函数打开文件 src_file,向其内写入“this is process 2\n”,之后等待 5 秒后退出;子进程 3 处理为守护进程,每隔 5 秒向日志文件/var/log/messages 写入“this is process 3\n”

提交形式

  1. 代码
  2. 运行结果截图
Read more »

Linux 常用命令

  • man: an interface to the on-line reference manuals
  • su [options] [username]: change user ID or become superuser
  • useradd [options] LOGIN: create a new user or update default new user information
  • userdel [options] LOGIN: delete a user account and related files
  • passwd [options] [LOGIN]: change user password
  • ps [options]: report a snapshot of the current process.
  • kill [options] […]: send a signal to a process
  • fdisk [options] device: manipulate disk partition table
  • mount: mount a filesystem
  • chown [OPTION] … [OWNER]:[GROUP]] FILE …: change file owner and group
  • chgrp [OPTION] … GROUP FILE …: change group ownership
  • chmod [OPTION] … MODE[,MODE] … FILE …: change file mode bits
  • grep [OPTION] PATTERN [FILE…]: print lines matching a pattern
  • find [-H] [-L] [-P] [-D debugopts] [-Olevel] [starting-point…] [expression]: search for files in a directory hierarchy
  • ln: make links between files
  • gzip, gunzip, zcat: compress or expand files
  • tar: an archiving utility
  • diff [OPTION] … FILES: compare files line by line
  • patch -pnum < patchfile: apply a diff file to an original
  • ifconfig: configure a network interface

文件类型

  • 普通文件
  • 目录文件
  • 链接文件:类似 Windows 的快捷方式,分软链接和硬链接
  • 设备文件:一般在/dev 目录下,一种是块设备文件,一种是字符设备文件

文件属性

-rwxrwxrwx

  • r: read
  • w: write
  • x: execute

第一个字符:

  • - : 普通文件
  • d : 目录文件
  • l : 链接文件
  • c : 字符设备
  • b : 块设备
  • p : 命名管道,如 FIFO
  • f : 堆栈文件,如 LIFO
  • s : 套接字

之后的三个三位字符组:

  1. 第一组代表文件拥有者(u)对该文件的权限
  2. 第二组代表文件用户组(g)对该文件的权限
  3. 第三组代表系统其它用户(o)对该文件的权限

文件系统类型

  • ext2 & ext3:ext3 是 ext2 的升级版本
  • swap:交换分区使用
  • vfat:DOS 中的系统(FAT12、FAT16 和 FAT32 等)
  • NFS:网络文件系统
  • ISO9660:光盘文件系统
Read more »

要求

  1. 程序 1 从串口读取信息,然后发到消息队列中。使用 2 个终端运行程序 1,创建出 2 个可从串口读取数据的进程,串口可以使用 Windows 中的虚拟串口,使用串口助手输入信息。
  2. 程序 2 从消息队列中读取消息,然后在屏幕上将消息内容显示出来。

提交形式

  1. 代码
  2. 运行结果截图、串口助手截图
Read more »

有名管道

  1. 父进程创建一个有名管道,然后创建 1 个子进程,父进程阻塞的方式等待有名管道的信息,当读取到信息之后,在屏幕上打印出来;当从有名管道中读取到“QUIT”之后,父进程终止。
  2. 子进程 1 使用定时器,每 5 秒钟向有名管道输入“this is process 1”;当收到信号 SIGQUIT 时,向有名管道输出“QUIT”,并在屏幕上输出“process 1 exit”之后,进程终止。

提交形式

  1. 代码
  2. 运行结果截图
Read more »