自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

unix/Linux低級(jí)IO函數(shù)的用法

系統(tǒng) Linux
unix/Linux 低級(jí)IO函數(shù)的用法,必須掌握寫module ,必要的應(yīng)用編程知識(shí)是應(yīng)該要有的, 否則 ,怎么寫應(yīng)用程序來(lái)測(cè)試你的module或者driver呢?

unix/Linux 低級(jí)IO函數(shù)的用法,必須掌握寫module ,必要的應(yīng)用編程知識(shí)是應(yīng)該要有的, 否則 ,怎么寫應(yīng)用程序來(lái)測(cè)試你的module或者driver呢?

而且最主要的是 , 了解上層調(diào)用的接口, 你就明白了上層的開(kāi)發(fā)者需要什么, 自己才好實(shí)現(xiàn)什么。

把手里的看書(shū)的事情都放下, 先把 Unix環(huán)境高級(jí)編程這本書(shū) 的第三章 徹底搞熟它。

內(nèi)容包括:

open() ,尤其是各種常見(jiàn)的參數(shù),到底是什么意思, 比如常用創(chuàng)建一個(gè)空文件: fd = open("/tmp/xx.txt",O_RDWR | O_CREAT | O_TRUNC);

讀一個(gè)文件,fd = open("/dev/hello",O_RDONLY );

如果就是要寫一個(gè)既有的文件,fd = open("/dev/hello",O_WRONLY );

具體的參數(shù): man 2 open

read(),

write()

ioctl() ,這個(gè)最重要。

lseek() , 文件指針移動(dòng)

#p#

比如下面的例子:

就是簡(jiǎn)單的讀一個(gè)文件:

#include

#include

#include

#include

int main(int argc,char **argv)

{

int fd = 0;

int pid = 0;

char buffer[20] = {'\0'};

char *read_buffer[20] = {'\0'};

//fd = open("/dev/hello",O_RDWR | O_CREAT | O_TRUNC);

fd = open("/dev/hello",O_RDONLY ); //| O_NONBLOCK);

printf("fd=%d\n",fd);

if(fd < 0) {

perror("/dev/hello");

return -1;

}

read(fd,read_buffer,sizeof(read_buffer)-1);

printf("read_buffer=%s\n",read_buffer);

close(fd);

return 0;

}

下面這個(gè)就是簡(jiǎn)單的寫一個(gè)文件 ,

#include

#include

#include

#include

int main(int argc,char **argv)

{

int fd = 0;

int pid = 0;

char buffer[20] = {'\0'};

char write_buffer[20] = {'\0'};

strcpy(write_buffer,"zhanglinbao");

fd = open("/dev/hello",O_RDWR | O_CREAT | O_TRUNC);

//fd = open("/dev/hello",O_RDONLY);

printf("fd=%d\n",fd);

if(fd < 0) {

perror("/dev/hello");

return -1;

}

write(fd,write_buffer,sizeof(write_buffer)-1);

close(fd);

return 0;

}

【編輯推薦】

  1. 如何優(yōu)化Linux服務(wù)器硬盤性能實(shí)用技巧
  2. 技巧:安裝linux后的內(nèi)核調(diào)優(yōu)
  3. 有備無(wú)患Linux操作系統(tǒng)的備份方法介紹
責(zé)任編輯:趙寧寧 來(lái)源: chinaitlab
相關(guān)推薦

2017-01-17 14:21:27

LinuxIO模型Unix

2012-02-22 21:54:57

UnixLinuxCron

2010-04-20 10:27:23

Unix操作系統(tǒng)

2011-09-05 17:44:49

LinuxUnix

2009-12-03 10:12:24

LinuxUnix

2021-06-21 11:11:29

LinuxIO磁盤IO

2010-05-11 11:29:11

Unix awk

2011-07-12 15:21:51

POSIX規(guī)范Linux

2009-09-29 10:45:17

UnixLinuxshell

2011-07-14 09:17:01

Unix數(shù)據(jù)中心

2010-03-08 09:27:55

Linux Unix區(qū)

2010-10-25 14:28:53

oracle trun

2010-10-25 16:52:48

oracle管道函數(shù)

2010-05-11 13:16:21

Unix awk

2020-12-07 10:30:39

LinuxUnix物聯(lián)網(wǎng)

2014-02-26 09:13:39

2013-07-23 17:26:07

2012-05-22 15:37:10

2020-05-12 16:58:05

LinuxUnix技術(shù)

2012-04-01 10:14:27

linuxunix
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)