欢迎来到天天文库
浏览记录
ID:37847505
大小:61.00 KB
页数:12页
时间:2019-06-01
《LINUX下CS模式学生管理系统》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、///semun.h#ifdefined(__GNU_LIBRARY__)&&!defined(_SEM_SEMUN_UNDEFINED)/*unionsemunisdefinedbyincluding*/#else/*accordingtoX/OPENwehavetodefineitourselves*/unionsemun{intval;/*valueforSETVAL*/structsemid_ds*buf;/*bufferforIPC_STAT,IPC_SET*/unsigned
2、shortint*array;/*arrayforGETALL,SETALL*/structseminfo*__buf;/*bufferforIPC_INFO*/};#endif///server.c#include#include#include#include#include#include#include#include
3、#include#include#include#include#include#include#include#include#include#include#include#include"semun.h"structstu_info{charstu_num[1
4、2];charname[10];charsex;/*0涓哄僐鐢燂紝1煱擑敺鐢?/charmobile_phone[12];};structstu_infostudent;unsignedintnumber;structstu_infostu[100];FILE*in;FILE*out;intlen;staticintsem_id;voidinputstu(intfd);voidupdatestu(intfd);voiddeletestu(intfd);voiddisplaystu(intfd);voidset
5、_semvalue();voiddel_semvalue();voidsemaphore_p();voidsemaphore_v();voidreaper(intsig);voidstuserver(intclient_sockfd);intmain(){srand((unsignedint)getpid());sem_id=semget((key_t)1234,1,0666
6、IPC_CREAT);set_semvalue();intserver_sockfd,client_sockfd;intserver_
7、len,client_len;structsockaddr_inserver_address;structsockaddr_inclient_address;server_sockfd=socket(AF_INET,SOCK_STREAM,0);server_address.sin_family=AF_INET;server_address.sin_addr.s_addr=htonl(INADDR_ANY);server_address.sin_port=htons(9734);server_len=size
8、of(server_address);bind(server_sockfd,(structsockaddr*)&server_address,server_len);listen(server_sockfd,5);signal(SIGCHLD,reaper);while(1){printf("serverwaiting");client_len=sizeof(client_address);client_sockfd=accept(server_sockfd,(structsockaddr*)&clien
9、t_address,&client_len);if(fork()==0){stuserver(client_sockfd);exit(0);}else{close(client_sockfd);}}del_semvalue();}voidstuserver(intclient_sockfd){charch;while(1){read(client_sockfd,&ch,1);if(ch=='q')b
此文档下载收益归作者所有