共 9 篇文章
显示摘要每页显示  条
/*控制球水平运动的变量*/int vdir; /*控制球垂直运动的变量*/int pos_X; /*球的横坐标*/int pos_Y; /*球的纵坐标*/ int delay=100;void moveBall();void init();void control();
信号量实现进程同步#include <sys/mman.h>#include <sys/types.h>#include <linux/sem.h>#include <fcntl.h>#include <unistd.h>#include <stdio.h>#include <errno.h>#include <time.h>#define MAXSEM 1.//声明3个信号量IDint fullid;int emptyid;int mutxid;//初始化P,V操作 P.sem_num=0; ...
} if(sigaddset(&set,SIGQUIT)<0) { perror("sigaddset SIGQUIT");} if(sigaddset(&set,SIGINT)<0) { perror("sigaddset SIGINT");} if(sigprocmask(SIG_BLOCK,&set,NULL)<0) { perror("sigprocmask,SIG_BLOCK");} if(sigprocmask(SIG_UNBLOCK,&set,NUL...
阻塞型信号通信#include<stdio.h>#include<unistd.h>#include<sys/types.h>#include<signal.h>#include<wait.h>pid_t pid;(pid=waitpid(-1,&status,WNOHANG))>0;if(a<0) { printf("创建进程出错!\n"); exit(1); } else if(a==0) { printf("child process'...
非阻塞型信号通信#include<stdio.h>#include<unistd.h>#include<sys/types.h>#include<signal.h>
命名管道#include<sys/types.h>#include<sys/stat.h>#include<stdio.h>#include<errno.h>#include<fcntl.h>#include<string.h>#define FIFO_SERVER "/tmp/fifoserver"#define BUFFERSIZE 80.} printf("fifoserver is created ...\n");if(fd==-1) { if(errno==ENXIO) ...
匿名管道#include<wait.h>#include<stdio.h>#include<unistd.h>#include<string.h>if(pipe(thePipe)==0) { if(fork()==0) { close(thePipe[1]);ret=read(thePipe[0],buf,MAX_LINE);ret=write(thePipe[1],testbuf,strlen(testbuf));printf("父进程写管道成功!\n"); close(thePipe[1]);...
用信号量解决“独木桥”问题:同一方向的行人可连续过桥,当某一方向有人过桥时,另一个方向的行人必须等待;将独木桥的两个方向标记为A和B,用变量countA和conutB表示A和B方向上已经在独木桥上的行人数目,初值为0;再设置三个互斥变量,初值都为1:SA实现对countA互斥修改,SB实现对countB变量的互斥修改,mutex用来实现两个方向的行人对独木...
帮助 | 留言交流 | 联系我们 | 服务条款 | 下载网文摘手 | 下载手机客户端
北京六智信息技术股份有限公司 Copyright© 2005-2024 360doc.com , All Rights Reserved
京ICP证090625号 京ICP备05038915号 京网文[2016]6433-853号 京公网安备11010502030377号
返回
顶部