freepeople性欧美熟妇, 色戒完整版无删减158分钟hd, 无码精品国产vα在线观看DVD, 丰满少妇伦精品无码专区在线观看,艾栗栗与纹身男宾馆3p50分钟,国产AV片在线观看,黑人与美女高潮,18岁女RAPPERDISSSUBS,国产手机在机看影片

正文內(nèi)容

嵌入式操作系統(tǒng)(編輯修改稿)

2024-08-03 13:55 本頁(yè)面
 

【文章內(nèi)容簡(jiǎn)介】 中include sys/ include sys/ include include include include define BUFFER_SIZE 1024 intmain(intargc,char**argv){ intfrom_fd,to_fd。 intbytes_read,bytes_write。 charbuffer[BUFFER_SIZE]。 char*ptr。 if(argc!=3){ fprintf(stderr,Usage:%sfromfiletofile\n\a,argv[0])。exit(1)。 } if((from_fd=open(argv[1],O_RDONLY))==1) { fprintf(stderr,Open%sError:%s\n,argv[1],strerror(errno))。 exit(1)。 } if((to_fd=open(argv[2],O_WRONLY|O_CREAT,S_IRUSR|S_IWUSR))==1){ fprintf(stderr,Open%sError:%s\n,argv[2],strerror(errno))。exit(1)。 } /* 以下代碼是一個(gè)經(jīng)典的拷貝文件的代碼 */ while(bytes_read=read(from_fd,buffer,BUFFER_SIZE)){ if((bytes_read==1)amp。amp。(errno!=EINTR))break。 elseif(bytes_read0){ ptr=buffer。 while(bytes_write=write(to_fd,ptr,bytes_read)){ if((bytes_write==1)amp。amp。(errno!=EINTR))break。 elseif(bytes_write==bytes_read)break。 elseif(bytes_write0) { ptr+=bytes_write。 bytes_read=bytes_write } } if(bytes_write==1)break。} } close(from_fd)。 close(to_fd)。 exit(0)。 }12.從鍵盤(pán)上輸入兩個(gè)學(xué)生的基本信息,然后 寫(xiě)入一個(gè)到文件中,最后讀出這兩個(gè)學(xué)生的數(shù)據(jù),并顯示在屏幕上。include struct student {char name[10]。 Int age。 }。int main(){ FILE *fp。 int i。struct student boya[2], boyb[2], *pp, *qq。if((fp = fopen(,w+))== NULL) { printf(Can not open file, exit ...\n)。return 1。} pp = boya; qq = boyb。 printf(please input data:\n)。 for (i = 0。 i 2。 i++, pp++) scanf(%s%d, ppname, amp。ppage)。 pp = boya。fwrite(pp, sizeof(struct student), 2, fp)。 rewind(fp)。 fread(qq, sizeof(struct student), 2, fp)。 printf(name\t\tage\n)。 for(i = 0。 i 2。 i++, qq++) printf(%s\t\t%d\n, qqname, qqage)。 fclose(fp)。 return 0。 }13.父進(jìn)程和子進(jìn)程之間創(chuàng)建了一個(gè)管道,建立之間的通信 (1) 將數(shù)據(jù)緩沖區(qū)清0 memset(buf_r,0,sizeof(buf_r)) (2) 創(chuàng)建管道 if(pipe(pipe_fd)0) (3) 創(chuàng)建子進(jìn)程 if((pid=fork())==0) (4) 關(guān)閉子進(jìn)程寫(xiě)描述符 close(pipe_fd[1])。(5) 子進(jìn)程讀取管道內(nèi)容 if((r_num=read(pipe_fd[0],buf_r,100))0) (6) 關(guān)閉子進(jìn)程讀描述符 close(pipe_fd[0]) (7) 父進(jìn)程運(yùn)行控制語(yǔ)句 else if(pid0) (8) 關(guān)閉父進(jìn)程的讀描述符close(pipe_fd[0]) (9) 將數(shù)據(jù)寫(xiě)入緩沖區(qū) if(write(pipe_fd[1],”hello”,5)!=1) (10) 關(guān)閉父進(jìn)程寫(xiě)描述符 close(pipe_fd[1]) 14.編程創(chuàng)建一個(gè)特定的IPC結(jié)構(gòu)的關(guān)鍵字和一個(gè)信號(hào)量,建立此信號(hào)量的索引,修改索引指向的信號(hào)量的值,最后清除信號(hào)量。void main() { key_t unique_key。 int id。 struct sembuf lock_it。union semun options。 int i。 unique_key = ftok(., 39。a39。)。 id = semget(unique_key, 1, IPC_CREAT | IPC_EXCL | 0666)。printf(semaphore id=%d\n, id)。 = 1。 semctl(id, 0, SETVAL, options)。 i = semctl(id, 0, GETVAL, 0)。printf(value of semaphore at index 0 is %d\n, i)。 = 0。 = 1。 = IPC_NOWAIT。 if (semop(id, amp。lock_it, 1) == 1) {printf(can not lock semaphore.\n)。exit(1)。}i = semctl(id, 0, GETVAL, 0)。printf(value of semaphore at index 0 is %d\n, i)。semctl(id, 0, IPC_RMID, 0)。}15.守護(hù)進(jìn)程編程。守護(hù)進(jìn)程實(shí)例包括兩部分:。主程序每隔一分鐘向/;初始化程序中init_daemon函數(shù)負(fù)責(zé)生成守護(hù)進(jìn)程??梢岳胕nit_daemon函數(shù)生成自己的守護(hù)進(jìn)程。(1) include include include sys/ include sys/ include sys/ void init_daemon(void) {int pid。 int i。 if(pid=fork()) exit(0)。 else if(pid 0) exit(1)。 setsid()。 if(pid=fork())exit(0)。 else if(pid 0) exit(1)。for(i=0。i NOFILE。++i) close(i)。 chdir(/tmp)。 umask(0)。return。 } (2) include include void init_daemon(void)。main() { FILE *fp。 time_t t。 init_daemon()。while(1){ sleep(60)。 if((fp=fopen(,a)) =0) { t=time(0)。 re at %s\n,asctime(localtime(amp。t)) )。 fclose(fp)。 } } } 編譯:gcc g o test 查看進(jìn)程:ps ef 進(jìn)程的各種特性滿足上面的要求。程序包括。創(chuàng)建無(wú)名管道、子進(jìn)程向父進(jìn)程寫(xiě)數(shù)據(jù)及關(guān)閉管道的讀端、父進(jìn)程從管道讀取子進(jìn)程寫(xiě)的數(shù)據(jù)及關(guān)閉管理的寫(xiě)端、讀有名管道和寫(xiě)有名管道 define INPUT 0 define OUTPUT 1void main() { int file_descriptors[2]。 pid_t pid。 char buf[256]。int returned_count。 pipe(file_descriptors)。if((pid = fork()) == 1) { printf(Error in fork\n)。 exit(1)。 }if(pid == 0) { printf(in the spawned (child) process...\n)。close(file_descriptors[INPUT])。write(file_descriptors[OUTPUT], test data, strlen(test data))。 exit(0)。} else { printf(in the spawning (parent) process...\n)。close(file_descriptors[OUTPUT])。returned_count = read(file_
點(diǎn)擊復(fù)制文檔內(nèi)容
黨政相關(guān)相關(guān)推薦
文庫(kù)吧 www.dybbs8.com
備案圖片鄂ICP備17016276號(hào)-1