Linux system programming 18 system call IO-fcntl and ioctl

fcntl(): All the magic that the file descriptor changes comes from this function

NAME
fcntl-manipulate file descriptor

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

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

Many IOs used are implemented by it, by encapsulating the function. I will not do a detailed interpretation for the time being, I will add it later. . .


ioctl(): device-related content

NAME
ioctl-control device

SYNOPSIS
#include <sys/ioctl.h>

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

/dev/fd: virtual directory, which displays the file descriptor information of the current process

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$ 

That is, the file descriptor information displayed is the file descriptor used by the ls command.

If you need to view the file descriptor information of the current process, you need to open /dev/fd/ to view it during the execution of the program.

Guess you like

Origin blog.csdn.net/LinuxArmbiggod/article/details/105906957