摘要:基本上和广播差不多,但服务器需要有加入多组播模块,运行的时候是./recv 224.10.10.1 5201 另开一个是./cli 224.10.10.1 5201
阅读全文
摘要:得到sockfd的时候是用数据报套接字,另外客服端需要设置广播属性
int on = 1;
Setsockopt(sockfd, SOL_SOCKET, SO_BROADCAST,&on, sizeof(on));
阅读全文
摘要:程序得到sockfd的时候需要设置成AF_LOCAL,后面地址是设置为路径;
阅读全文
摘要:带外数据(紧急数据),服务器注册信号,signal(SIGURG, catch_sig);然后再处理函数中recv;客服端发带外数据的时候只能用send,如(sockfd, "4", 1, MSG_OOB);
阅读全文
摘要:加锁后,另外的线程就不能来访问临界资源了,只有释放锁之后才行!
阅读全文
摘要:子线程会等到主线程执行了V操作后才能往下执行
阅读全文
摘要:创建线程,记得编译的时候是 gcc pthread.c -o pthread -lpthread
阅读全文
摘要:对于临界资源,p,v操作可以保证正在执行的操作不会被另外的进程嵌套进来!
阅读全文
摘要:#include<stdio.h>#include<stdlib.h>#include<unistd.h>#include<sys/types.h>#include<sys/ipc.h>#include<sys/shm.h>int main(){pid_t t;int shmid;shmid = shmget(IPC_PRIVATE, 1024, 0666);//创建共享内存system("ipcs -m");t = fork();if(t == 0){//childsleep(3);char *b;b
阅读全文
摘要:1:#include<stdio.h>#include<stdlib.h>#include<signal.h>void f(int reg){printf("the signal handle!\n");}int main(){signal(SIGINT, f);//注册一个信号,接收到时进入处理函数fpause();return 0;}2:#include<stdio.h>#include<stdlib.h>#include<signal.h>#include<sys/types.h>#i
阅读全文
摘要:写程序#include<stdio.h>#include<stdlib.h>#include<string.h>#include<unistd.h>#include<sys/types.h>#include<sys/stat.h>#include<fcntl.h>int main(){int f;int fd;//char buff[10];f = mkfifo("myfifo",06666);//创建有名管道char buf[] = "abcd";fd = open(&
阅读全文
摘要:#include<stdio.h>#include<stdlib.h>#include<unistd.h>#include<string.h>int main(){pid_t pid;int pipefd[2];pipe(pipefd);pid = fork();if(pid == 0){//子进程char buf_2[20];bzero(buf_2, 20);sleep(2);read(pipefd[0], buf_2, 17);//从管道的读端读出数据printf("%s",buf_2);close(pipefd[0]);
阅读全文
摘要:#include<stdio.h>#include<stdlib.h>#include<unistd.h>#include<sys/wait.h>#include<sys/types.h>int main(){pid_t t;char buf[] = "test!";t = fork();//创建一个子进程 if(t == 0){printf("child\n");printf("C: %s\n",buf);execlp("ls","ls&quo
阅读全文