Linux系统编程18 系统调用IO - fcntl和ioctl

fcntl():文件描述符所变化的所有魔术都来源于该函数

NAME
fcntl - manipulate file descriptor 管理文件描述符

SYNOPSIS
#include <unistd.h>
#include <fcntl.h>

   int fcntl(int fd, int cmd, ... /* arg */ );

很多用到的IO 都是有它实现,通过封装该函数。暂时不做详细解读,后面回补充。。。


ioctl() :设备相关的内容

NAME
ioctl - control device 控制设备

SYNOPSIS
#include <sys/ioctl.h>

   int ioctl(int fd, unsigned long request, ...);

/dev/fd :虚目录,显示的是当前进程的文件描述符信息

mhr@ubuntu:~/work/linux/sysio/17$ 
mhr@ubuntu:~/work/linux/sysio/17$ ls -l /dev/fd/
total 0
lrwx------ 1 mhr mhr 64 May  3 03:49 0 -> /dev/pts/4
lrwcx------ 1 mhr mhr 64 May  3 03:49 1 -> /dev/pts/4
lrwx------ 1 mhr mhr 64 May  3 03:49 2 -> /dev/pts/4
lr-x------ 1 mhr mhr 64 May  3 03:49 3 -> /proc/8841/fd
mhr@ubuntu:~/work/linux/sysio/17$ 

即显示的文件描述符信息是 ls命令 所用到的文件描述符的情况。

如果需要看当前进程的文件描述符信息,则需要在程序执行的过程当中,打开 /dev/fd/ 查看。

猜你喜欢

转载自blog.csdn.net/LinuxArmbiggod/article/details/105906957