共 9 篇文章 |
|
/*控制球水平运动的变量*/int vdir; /*控制球垂直运动的变量*/int pos_X; /*球的横坐标*/int pos_Y; /*球的纵坐标*/ int delay=100;void moveBall();void init();void control(); 阅2493 转190 评0 公众公开 12-01-11 14:56 |
信号量实现进程同步#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; ... 阅540 转5 评0 公众公开 11-11-26 09:10 |
} 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... 阅87 转1 评0 公众公开 11-10-25 09:36 |
阻塞型信号通信#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'... 阅124 转6 评0 公众公开 11-10-25 09:36 |
非阻塞型信号通信#include<stdio.h>#include<unistd.h>#include<sys/types.h>#include<signal.h> 阅122 转8 评0 公众公开 11-10-25 09:36 |
命名管道#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) ... 阅207 转1 评0 公众公开 11-10-16 13:02 |
匿名管道#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]);... 阅296 转0 评0 公众公开 11-10-16 13:01 |
阅57 转0 评0 公众公开 11-10-11 11:05 |
用信号量解决“独木桥”问题:同一方向的行人可连续过桥,当某一方向有人过桥时,另一个方向的行人必须等待;将独木桥的两个方向标记为A和B,用变量countA和conutB表示A和B方向上已经在独木桥上的行人数目,初值为0;再设置三个互斥变量,初值都为1:SA实现对countA互斥修改,SB实现对countB变量的互斥修改,mutex用来实现两个方向的行人对独木... 阅899 转12 评0 公众公开 11-10-11 09:19 |