国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

IO進程線程day8(2023.8.6)

這篇具有很好參考價值的文章主要介紹了IO進程線程day8(2023.8.6)。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點擊"舉報違法"按鈕提交疑問。

一、Xmind整理:

管道的原理:

IO進程線程day8(2023.8.6),myeclipse,ide,java

有名管道的特點:?

IO進程線程day8(2023.8.6),myeclipse,ide,java

信號的原理:

IO進程線程day8(2023.8.6),myeclipse,ide,java

二、課上練習:

練習1:pipe

功能:創(chuàng)建一個無名管道,同時打開無名管道的讀寫端
原型:
#include <unistd.h>
int pipe(int pipefd[2]); int* pfd;  int pfd[]
參數(shù):
int pipefd[2]:函數(shù)運行完畢后,該參數(shù)指向的數(shù)組中會存儲兩個文件描述符;
pipefd[0]:    讀端文件描述符;
pipefd[1]:    寫端文件描述符;
返回值:
成功,返回0;
失敗,返回-1,更新errno;
小練:?
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <head.h>
int main(int argc, const char *argv[])
{
    //管道的創(chuàng)建必須放在fork函數(shù)前
    //若放在fork函數(shù)后,會導致父子進程各自創(chuàng)建一根管道
    //此時會導致父子進程各自操作各自的管道,無法進行通信
    int pfd[2] = {0};
    if(pipe(pfd) < 0)
    {
        perror("pfd");
        return -1;
    }
    printf("pipe success pfd[0]=%d pfd[1]=%d\n",pfd[0],pfd[1]);
    
    pid_t cpid = fork();
    if(cpid > 0)  //父進程中為真
    {
        //父進程發(fā)送數(shù)據(jù)給子進程
        char buf[128]="";
        while(1)
        {
            fgets(buf,sizeof(buf),stdin);
            buf[strlen(buf)-1] = 0;     //從終端獲取數(shù)據(jù),最后會拿到\n字符,將\n字符修改成0

            //將數(shù)據(jù)寫入到管道文件中
            if(write(pfd[1],buf,sizeof(buf)) < 0)
            {
                perror("write");
                return -1;
            }
            printf("寫入成功\n");
        
        }
    }
    else if(0 == cpid)      //子進程中為真
    {
        //子進程讀取父進程發(fā)送過來的數(shù)據(jù)
        char buf[128] = "";
        ssize_t res = 0;
        while(1)
        {
            bzero(buf,sizeof(buf));
            printf("__%d__\n",__LINE__);
            //當管道中沒有數(shù)據(jù)的時候,read函數(shù)阻塞
            res = read(pfd[0],buf,sizeof(buf));
            printf("res=%ld : %s\n",res,buf);                                                         
        }
    }
    else
    {
        perror("fork");
        return -1;
    }

    return 0;
}

IO進程線程day8(2023.8.6),myeclipse,ide,java

練習2:mkfifo

功能:創(chuàng)建一根有名管道
原型:
#include <sys/types.h>
#include <sys/stat.h>
int mkfifo(const char *pathname, mode_t mode);
參數(shù):
char *pathname:指定要創(chuàng)建的有名管道的路徑以及名字;
mode_t mode:有名管道的權(quán)限:0664 0777,真實的權(quán)限 (mode & ~umask)
the  permissions of the created file are (mode & ~umask)
返回值:
成功,返回0;
失敗,返回-1,更新errno;
errno == 17,文件已經(jīng)存在的錯誤,這是一個允許存在的錯誤,忽略該錯誤

練習3:操作有名管道

功能:操作有名管道與用文件IO操作普通文件一致
原型:
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
int open(const char *pathname, int flags);
參數(shù):
  int flags:
       O_RDONLY  只讀
       O_WRONLY  只寫
       O_RDWR    讀寫
  ---上述三種必須,且只能包含一種---
       O_NONBLOCK     非阻塞

1.int flags == O_RDONLY

? ? open函數(shù)阻塞,此時需要另外一個進程或線程以寫的方式打開同一根管道,open函數(shù)解除阻塞

2.int flags == O_WRONLY

? ?open函數(shù)阻塞,此時需要另外一個進程或線程以讀的方式打開同一根管道,open函數(shù)解除阻塞

3.int flags == O_RDWR

? ?open函數(shù)不阻塞,此時管道的讀寫端均被打開

? ?當管道的讀寫端均被打開的時候,此時open函數(shù)不阻塞

4.int flags == O_RDONLY | O_NONBLOCK

? ?open函數(shù)不阻塞,open函數(shù)運行成功,此時管道只有讀端

5.int flags == O_WRONLY | O_NONBLOCK

? ?open函數(shù)不阻塞,open函數(shù)運行失敗,此時管道的讀寫端均打開失敗?

示例:?
讀端:
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>
#include <unistd.h>
#include <string.h>

int main(int argc, const char *argv[])
{
    umask(0);

    if(mkfifo("./fifo", 0777) < 0)
    {
        //printf("errno = %d\n", errno);
        if(errno != 17)     //17 == EEXIST
        {
            perror("mkfifo");
            return -1;
        }
    }
    printf("create FIFO success\n");

    //open函數(shù)阻塞
    int fd = open("./fifo", O_RDONLY);
    if(fd < 0)
    {
        perror("open");
        return -1;
    }
    printf("open FIFO rdonly success  fd=%d\n", fd);

    char buf[128] = "";
    ssize_t res = 0;
    while(1)
    {
        bzero(buf, sizeof(buf));
        res = read(fd, buf, sizeof(buf));
        if(res < 0)
        {
            perror("read");
            return -1;                                  
        }
        else if(0 == res)
        {
            printf("對端關(guān)閉\n");
            break;
        }

        printf("%ld :%s\n", res, buf);
    }

    close(fd);

    return 0;
}
寫端:
#include <stdio.h>                                    
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>
#include <unistd.h>
#include <string.h>

int main(int argc, const char *argv[])
{
    umask(0);

    if(mkfifo("./fifo", 0777) < 0)
    {   
        //printf("errno = %d\n", errno);
        if(errno != 17)     //17 == EEXIST
        {
            perror("mkfifo");
            return -1; 
        }
    }   
    printf("create FIFO success\n");

    //open函數(shù)阻塞
    int fd = open("./fifo", O_WRONLY);
    if(fd < 0)
    {   
        perror("open");
        return -1; 
    }   
    printf("open FIFO wronly success  fd=%d\n", fd);

    char buf[128] = ""; 
    while(1)
    {   
        printf("請輸入>>>");
        fgets(buf, sizeof(buf), stdin);
        buf[strlen(buf)-1] = 0;

        if(write(fd, buf, sizeof(buf)) < 0)
        {
            perror("write");
            return -1; 
        }
        printf("寫入成功\n");
    }   

    close(fd);

    return 0;
}
小練:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <head.h>                                                                         
int main(int argc, const char *argv[])
{
    //創(chuàng)建有名管道
    if(mkfifo("./fifo",0664) < 0)
    {
        //printf("%d\n",errno);
        if(errno != 17)    //17:文件已經(jīng)存在錯誤,這是一個允許存在的錯誤,忽略該錯誤
        {
            perror("mkfifo");
            return -1;
        }
    }
    printf("mkfifo success\n");

/*
    int fd = open("./fifo",O_RDWR);
    if(fd <  0)
    {
        perror("open");
        return -1;
    }
    printf("open success fd = %d\n",fd);
*/

    int fd_r = open("./fifo",O_RDONLY|O_NONBLOCK);
    if(fd_r <  0)
    {
        perror("open");
        return -1;
    }
    printf("open success fd_r = %d\n",fd_r);

    int fd_w = open("./fifo",O_WRONLY|O_NONBLOCK);
    if(fd_w <  0)
    {
        perror("open");
        return -1;
    }
    printf("open success fd_w = %d\n",fd_w);

    return 0;
}

IO進程線程day8(2023.8.6),myeclipse,ide,java

練習4:常見的信號

IO進程線程day8(2023.8.6),myeclipse,ide,java

練習5:signal

功能:捕獲信號,為信號注冊新的處理函數(shù)
原型:
#include <signal.h>
typedef void (*sighandler_t)(int);
sighandler_t signal(int signum, sighandler_t handler);     //void (*handler)(int);
參數(shù):
int signum:指定要捕獲的信號對應的編號??梢蕴罹幪枺部梢蕴顚暮?。2) SIGINT
sighandler_t handler:函數(shù)指針,回調(diào)函數(shù);
1) SIG_IGN:忽略信號;     9) 19)號信號無法忽略;
2) SIG_DFL:執(zhí)行默認操作;
3) 傳入一個函數(shù)的首地址,代表捕獲信號,且該函數(shù)的返回值必須是void類型,參數(shù)列表必須是int類型,例如:
                void handler(int sig){                                    
                }
typedef void (*sighandler_t)(int);     typedef void (*)(int)   sighandler_t; 
typedef 舊的類型名  新的類型名;
typedef int uint32_t;                  int a ----> uint32_t a;
typedef int*    pint;                  int* pa ---> pint pa;
typedef void (*)(int)   sighandler_t;  void (*ptr)(int) ----> sighandler_t ptr;
返回值:
成功,返回該信號的上一個信號處理函數(shù)的首地址; 默認處理函數(shù)的首地址獲取不到,返回NULL;
失敗,返回SIG_ERR ((__sighandler_t)-1),更新errno;      

注意:當在某個信號A的信號處理函數(shù)中時,再次觸發(fā)信號A,此時信號A的處理函數(shù)不會再次被載入運行,即第二次觸發(fā)的信號A被屏蔽。但是此時若觸發(fā)了信號B,信號B的處理函數(shù)是可以正常被載入的,即沒有屏蔽信號B。

小練:?
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <signal.h>
#include <head.h>
void handler(int sig)
{
    printf("this is sig=%d\n",sig);
    return;
}
int main(int argc, const char *argv[])
{
    //捕獲2號SIGINT信號
    if(signal(2,handler) == SIG_ERR)
    {
        perror("signal");
        return -1;
    }
    printf("捕獲2號信號成功\n");
                                           
    //捕獲3號SIGINT信號
    if(signal(3,handler) == SIG_ERR)
    {
        perror("signal");
        return -1;
    }
    printf("捕獲3號信號成功\n");

    //捕獲20號SIGINT信號
    if(signal(20,handler) == SIG_ERR)
    {
        perror("signal");
        return -1;
    }
    printf("捕獲20號信號成功\n");

    while(1)
    {
        printf("this is main func\n");
        sleep(1);
    }

    return 0;
}
                                           

IO進程線程day8(2023.8.6),myeclipse,ide,java

三、課后作業(yè):

1.要求實現(xiàn)AB進程對話

? ?A進程先發(fā)送一句話給B進程,B進程接收后打印

? ?B進程再回復一句話給A進程,A進程接收后打印

? ?重復1.2步驟,當收到quit后,要結(jié)束AB進程

? ?提示:兩根管道

A進程:?
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <head.h>                                                                                       
int main(int argc, const char *argv[])
{
    //創(chuàng)建有名管道
    if(mkfifo("./fifo",0664) < 0)
    {
        //printf("%d\n",errno);
        if(errno != 17)    //17:文件已經(jīng)存在錯誤,這是一個允許存在的錯誤,忽略該錯誤
        {
            perror("mkfifo");
            return -1;
        }
    }
    printf("mkfifo success\n");

    if(mkfifo("./fifo1",0664) < 0)
    {
        //printf("%d\n",errno);
        if(errno != 17)    //17:文件已經(jīng)存在錯誤,這是一個允許存在的錯誤,忽略該錯誤
        {
            perror("mkfifo");
            return -1;
        }
    }
    printf("mkfifo1 success\n");

    int fd_r= open("./fifo",O_RDONLY);
    if(fd_r <  0)
    {
        perror("open");
        return -1;
    }
    printf("open success fd_r = %d\n",fd_r);

    int fd_w = open("./fifo1",O_WRONLY);
    if(fd_w <  0)
    {
        perror("open");
        return -1;
    }
    printf("open success fd_w= %d\n",fd_w);

    //從管道中讀取數(shù)據(jù),打印到終端上
    char buf[128]="";
    ssize_t res = 0;
    while(1)
    {
        bzero(buf,sizeof(buf));
        //當管道的讀寫端均存在,若管道中沒有數(shù)據(jù),則read函數(shù)阻塞
        res = read(fd_r,buf,sizeof(buf));
        if(strcmp(buf,"quit") == 0)
        {
            write(fd_w,buf,sizeof(buf));
            break;
        }
        if(res < 0)
        {
            perror("read");
            return -1;
        }
        if(0 == res)
        {
            printf("寫端關(guān)閉\n");
            break;
        }
        printf("res =%ld\n輸出:%s\n",res,buf);

        bzero(buf, sizeof(buf));
        printf("請輸入:");
        fgets(buf, sizeof(buf),stdin);
        buf[strlen(buf)-1] = '\0';

        if(write(fd_w,buf,sizeof(buf))< 0)
        {
            perror("write");
            return -1;
        }
        printf("寫入數(shù)據(jù)成功  res =%ld\n",res);

    }

    close(fd_r);
    close(fd_w);
    return 0;
}
B進程:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <head.h>
int main(int argc, const char *argv[])
{
    //創(chuàng)建有名管道
    if(mkfifo("./fifo",0664) < 0)
    {
        //printf("%d\n",errno);
        if(errno != 17)    //17:文件已經(jīng)存在錯誤,這是一個允許存在的錯誤,忽略該錯誤
        {
            perror("mkfifo");
            return -1;
        }
    }
    printf("mkfifo success\n");

    if(mkfifo("./fifo1",0664) < 0)
    {
        //printf("%d\n",errno);
        if(errno != 17)    //17:文件已經(jīng)存在錯誤,這是一個允許存在的錯誤,忽略該錯誤
        {
            perror("mkfifo");
            return -1;
        }
    }
    printf("mkfifo1 success\n");

    int fd_w = open("./fifo",O_WRONLY);
    if(fd_w <  0)
    {
        perror("open");
        return -1;
    }
    printf("open success fd_w= %d\n",fd_w);

    int fd_r= open("./fifo1",O_RDONLY);                                                                                                       
    if(fd_r <  0)
    {
        perror("open");
        return -1;
    }
    printf("open success fd_r = %d\n",fd_r);

    //從終端獲取數(shù)據(jù),寫到管道中
    char buf[128]="";
    ssize_t res = 0;
    while(1)
    {
        bzero(buf, sizeof(buf));
        printf("請輸入:");
        fgets(buf,sizeof(buf),stdin);
        buf[strlen(buf)-1] = '\0';
        if(strcmp(buf,"quit") == 0)
        {
            write(fd_w,buf,sizeof(buf));
            break;
        }
        if(write(fd_w,buf,sizeof(buf)) < 0)
        {
            perror("write");
            return -1;
        }
        printf("寫入數(shù)據(jù)成功  res =%ld\n",res);

        bzero(buf,sizeof(buf));
        //當管道的讀寫端均存在,若管道中沒有數(shù)據(jù),則read函數(shù)阻塞
        res = read(fd_r,buf,sizeof(buf));
        if(res < 0)
        {
            perror("read");
            return -1;
        }
        if(0 == res)
        {
            printf("寫端關(guān)閉\n");
            break;
        }
        printf("res =%ld\n輸出:%s\n",res,buf);
    }

    close(fd_w);
    close(fd_r);

    return 0;
}

IO進程線程day8(2023.8.6),myeclipse,ide,java

2.在第1題的基礎(chǔ)上實現(xiàn),A能隨時發(fā)信息給B,B能隨時接收A發(fā)送的數(shù)據(jù),反之亦然。

A進程:
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <errno.h>
#include <fcntl.h>
#include <string.h>
#include <sys/wait.h>
#include <signal.h>

int main(int argc, const char *argv[])
{
	if(mkfifo("./fifo", 0775) < 0) 	 	//當前進程寫該管道
	{
		if(17 != errno) 	//#define EEXIST      17
		{
			perror("mkfifo");
			return -1;
		}
	}

	printf("fifo create success\n");

	if(mkfifo("./fifo1", 0775) < 0)     //當前進程讀該管道
	{
		if(17 != errno)     //#define EEXIST      17
		{
			perror("mkfifo");
			return -1;
		}
	}

	printf("fifo1 create success\n");



	//創(chuàng)建一個子進程
	pid_t cpid = fork();
	if(cpid > 0)
	{
		//讀  fifo1
		int fd_r = open("./fifo1", O_RDONLY);    //阻塞
		if(fd_r < 0)
		{
			perror("open");
			return -1;
		}
		printf("open fifo rdonly success __%d__\n", __LINE__);

		ssize_t res = 0;
		char buf[128] = "";
		while(1)
		{
			bzero(buf, sizeof(buf));
			//讀寫段均存在,且管道中沒有數(shù)據(jù),該函數(shù)阻塞
			res = read(fd_r, buf, sizeof(buf));
			if(res < 0)
			{
				perror("read");
				return -1;
			}
			else if(0 == res)
			{
				printf("對端進程退出\n");
				break;                                      
			}
			printf("res=%ld : buf=%s\n", res, buf);

			if(!strcmp(buf, "quit"))
				break;
		}


		close(fd_r);
		kill(cpid, 9);

		wait(NULL);

	}
	else if(0 == cpid)
	{
		//寫 fifo
		int fd_w = open("./fifo", O_WRONLY);  //阻塞
		if(fd_w < 0)
		{
			perror("open");
			return -1;
		}
		printf("open fifo wronly success __%d__\n", __LINE__);

		char buf[128] = "";
		while(1)
		{
			bzero(buf, sizeof(buf));

		//	printf("請輸入>>>");
			fgets(buf, sizeof(buf), stdin);
			buf[strlen(buf)-1] = 0;

			if(write(fd_w, buf, sizeof(buf)) < 0)
			{
				perror("write");
				return -1;
			}
		//	printf("寫入成功\n");

			if(!strcmp(buf, "quit"))
				break;

		}

		close(fd_w);
		kill(getppid() , 9);
	}
	else
	{
		perror("fork");
		return -1;
	}

	return 0;
}
B進程:
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <errno.h>
#include <fcntl.h>
#include <string.h>
#include <sys/wait.h>
#include <signal.h>

int main(int argc, const char *argv[])
{
	if(mkfifo("./fifo", 0775) < 0) 	 	//當前進程寫該管道
	{
		if(17 != errno) 	//#define EEXIST      17
		{
			perror("mkfifo");
			return -1;
		}
	}

	printf("fifo create success\n");

	if(mkfifo("./fifo1", 0775) < 0)     //當前進程讀該管道
	{
		if(17 != errno)     //#define EEXIST      17
		{
			perror("mkfifo");
			return -1;
		}
	}

	printf("fifo1 create success\n");



	//創(chuàng)建一個子進程
	pid_t cpid = fork();
	if(cpid > 0)
	{
		//讀  fifo
		int fd_r = open("./fifo", O_RDONLY);    //阻塞
		if(fd_r < 0)
		{
			perror("open");
			return -1;
		}
		printf("open fifo rdonly success __%d__\n", __LINE__);

		ssize_t res = 0;
		char buf[128] = "";
		while(1)
		{
			bzero(buf, sizeof(buf));
			//讀寫段均存在,且管道中沒有數(shù)據(jù),該函數(shù)阻塞
			res = read(fd_r, buf, sizeof(buf));
			if(res < 0)
			{
				perror("read");
				return -1;
			}
			else if(0 == res)
			{
				printf("對端進程退出\n");
				break;                                      
			}
			printf("res=%ld : buf=%s\n", res, buf);

			if(!strcmp(buf, "quit"))
				break;
		}

		close(fd_r);
		kill(cpid, 9);

		wait(NULL);

	}
	else if(0 == cpid)
	{
		//寫 fifo1
		int fd_w = open("./fifo1", O_WRONLY);  //阻塞
		if(fd_w < 0)
		{
			perror("open");
			return -1;
		}
		printf("open fifo wronly success __%d__\n", __LINE__);

		char buf[128] = "";
		while(1)
		{
			bzero(buf, sizeof(buf));

			//printf("請輸入>>>");
			fgets(buf, sizeof(buf), stdin);
			buf[strlen(buf)-1] = 0;

			if(write(fd_w, buf, sizeof(buf)) < 0)
			{
				perror("write");
				return -1;
			}
		//	printf("寫入成功\n");

			if(!strcmp(buf, "quit"))
				break;
		}

		close(fd_w);
		kill(getppid() , 9);

	}
	else
	{
		perror("fork");
		return -1;
	}

	return 0;
}

IO進程線程day8(2023.8.6),myeclipse,ide,java文章來源地址http://www.zghlxwxcb.cn/news/detail-629907.html

到了這里,關(guān)于IO進程線程day8(2023.8.6)的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務(wù),不擁有所有權(quán),不承擔相關(guān)法律責任。如若轉(zhuǎn)載,請注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實不符,請點擊違法舉報進行投訴反饋,一經(jīng)查實,立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費用

相關(guān)文章

  • 2023.08.01 驅(qū)動開發(fā)day8

    2023.08.01 驅(qū)動開發(fā)day8

    驅(qū)動層 應用層?

    2024年02月14日
    瀏覽(14)
  • 數(shù)據(jù)結(jié)構(gòu)day8(2023.7.25)

    數(shù)據(jù)結(jié)構(gòu)day8(2023.7.25)

    排序:把無需序列轉(zhuǎn)換為有序序列的一種算法。 內(nèi)排:在計算機內(nèi)存中實現(xiàn)的排序算法【多用適用于數(shù)據(jù)量較小的情況】 外排:在計算機內(nèi)存以及外部介質(zhì)實現(xiàn)的排序算法【先內(nèi)存,在外部】 排序的分類: 交換排序:冒泡排序、快速排序 插入排序:直接插入排序,希爾排

    2024年02月15日
    瀏覽(12)
  • C/C++進程超詳細詳解【下部分】(系統(tǒng)性學習day8)

    C/C++進程超詳細詳解【下部分】(系統(tǒng)性學習day8)

    前言 一,有名管道通信 1 .概念 2 .創(chuàng)建有名管道 實例代碼如下: 二、信號通信 1 .概念 2 .用戶進程對信號的響應方式 3. 用戶進程對常用信號的缺省操作 4. 信號處理流程 5. 信號相關(guān)函數(shù)(系統(tǒng)調(diào)用) ?5.1 kill - 給指定進程發(fā)送信號 實例代碼如下:? 5.2 raise() --給當前進程發(fā)送信

    2024年02月08日
    瀏覽(20)
  • 前端學習記錄~2023.7.16~CSS雜記 Day8

    前端學習記錄~2023.7.16~CSS雜記 Day8

    由于有很多知識非常符合直覺或者和其他語言有通用性,因此個人覺得不需要全部記下來,本篇只記錄一些個人覺得需要注意或單獨記憶的知識點。 同時為了提高效率和減少對不重要內(nèi)容的時間投入,會考慮更加精簡。 相比上一篇總覽,本篇更詳細記錄了正常布局流、彈性

    2024年02月17日
    瀏覽(19)
  • IO 與進程線程

    2023年05月28日
    瀏覽(25)
  • IO進程線程,文件IO(open),文件(stat)與目錄(opendir)屬性的讀取

    IO進程線程,文件IO(open),文件(stat)與目錄(opendir)屬性的讀取

    ? ? ? 一、文件IO 1、文件io通過系統(tǒng)調(diào)用來操作文件 系統(tǒng)調(diào)用:系統(tǒng)提供給用戶的一組API(接口函數(shù)) ??????? open/read/write/close/lseek... 用戶空間進程訪問內(nèi)核的接口 把用戶從底層的硬件編程中解放出來 極大的提高了系統(tǒng)的安全性 使用戶程序具有可移植性(同一系統(tǒng)下) 是操作

    2024年02月11日
    瀏覽(30)
  • IO進程線程第五天(8.2)進程函數(shù)+XMind(守護進程(幽靈進程),輸出一個時鐘,終端輸入quit時退出時鐘)

    IO進程線程第五天(8.2)進程函數(shù)+XMind(守護進程(幽靈進程),輸出一個時鐘,終端輸入quit時退出時鐘)

    1.守護進程(幽靈進程) 2.輸出一個時鐘,終端輸入quit時退出時鐘 ? ? ? ?

    2024年02月14日
    瀏覽(20)
  • IO進程線程,文件與目錄,實現(xiàn)linux任意目錄下ls -la

    注意文件的名字、路徑是如何輸入的。 函數(shù)opendir打開目錄,struct dirent,struct stat這些結(jié)構(gòu)體的含義。? ????????readdir()函數(shù)是一個用于讀取目錄內(nèi)容的系統(tǒng)調(diào)用或庫函數(shù),在類Unix操作系統(tǒng)中(如Linux)廣泛使用。它用于遍歷目錄,并逐個獲取目錄中的條目(文件和子目錄

    2024年02月10日
    瀏覽(23)
  • 2023年7月18日,File類,IO流,線程

    2023年7月18日,File類,IO流,線程

    File,是文件和目錄路徑的抽象表示 File只關(guān)注文件本身的信息,而不能操作文件里的內(nèi)容 。如果需要讀取或?qū)懭胛募?nèi)容,必須使用 IO 流來完成。 在Java中, java.io.File 類用于表示文件或目錄的抽象路徑名。它提供了一組方法,可以用于創(chuàng)建、訪問、重命名、刪除文件或目錄

    2024年02月17日
    瀏覽(17)
  • 驅(qū)動開發(fā)—day8

    1、在內(nèi)核模塊中啟用定時器,定時1s,讓led1 閃爍 2、基于gpio子系統(tǒng)完成led燈驅(qū)動的注冊,應用程序測試 應用層代碼:

    2024年02月15日
    瀏覽(18)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包