- 博客(29)
- 收藏
- 关注
原创 信号量实验
#include <unistd.h> #include <stdlib.h> #include <stdio.h> #include <sys/sem.h>//包含信号量定义的头文件 //联合类型semun定义 union semun{ int val; struct semid_ds *buf; unsigned short *array;...
2022-01-07 01:29:12
133
原创 pthread10
/* pthread10.c 信号量 */#include <stdio.h>#include <pthread.h> #include <semaphore.h> #define MAXSTACK 100 int stack[MAXSTACK][2]; int size=0; sem_t sem; /* 从文件1.dat读取数据,每读一次,信号量加一*/ void ReadData1(void){ FILE ...
2022-01-05 00:18:57
579
原创 11111111
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 ...
2022-01-04 18:09:45
150
原创 tcp.client
#include <stdlib.h>#include <stdio.h>#include <errno.h>#include <string.h>#include <netdb.h>#include <sys/types.h>#include <netinet/in.h>#include <sys/socket.h>#define portnumber 3333int
2022-01-04 15:06:16
99
原创 9string
#include <pthread.h>#include <stdio.h>#include <unistd.h>void *create(void *arg){ char *name; name=(char *)arg; printf("The parameter passed from main function is %s \n",name); return (void *)0;}int ma...
2022-01-04 09:22:56
263
原创 9share
#include <stdio.h>#include <pthread.h>#include <unistd.h>static int a=99;void *create(void *arg){ printf("new pthread ... \n"); printf("in thread a=%d \n",a); return (void *)0;}int main(int argc,char *a...
2022-01-04 09:14:51
266
原创 pthread9
/* pthread9.c 条件变量*/#include <pthread.h>#include <stdio.h>#include <stdlib.h>pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;/*初始化互斥锁*/pthread_cond_t cond = PTHREAD_COND_INITIALIZER;/*初始化条件变量*/void *thread1(void *);voi
2022-01-04 08:59:20
52
原创 pthread9.2
/* pthread9-2.c 条件变量(生产者与消费者的关系)*/#include <pthread.h>#include <stdio.h>pthread_mutex_t mutex=PTHREAD_MUTEX_INITIALIZER;pthread_cond_t cond=PTHREAD_COND_INITIALIZER;int count=5;void *decrement(void *arg)//消费{ while(1) {..
2022-01-04 08:35:01
51
原创 实验3代码
#include<semaphore.h>#include<sys/types.h>#include<stdio.h>#include<unistd.h>#include<pthread.h>int number;sem_t sem_id1,sem_id2;pthread_t id1,id2;int g_flag=0;void *thread_one_func(void *arg){ sem_wait(&se...
2021-12-26 09:44:11
58
原创 8.14.4
#include <unistd.h>#include <sys/types.h>#include <sys/socket.h>#include <netinet/in.h>#include <arpa/inet.h>#include <stdlib.h>#include <stdio.h>#include <errno.h>#include <string.h>#define
2021-12-23 15:42:28
49
原创 8.14.3
/*创建套接字;填充;绑定;监听;接受*/#include <unistd.h>#include <sys/types.h>#include <sys/socket.h>#include <netinet/in.h>#include <arpa/inet.h>#include <stdlib.h>#include <stdio.h>#include <errno.h>#include <
2021-12-23 15:41:56
58
原创 8.14.2
#include <unistd.h>#include <sys/types.h>#include <sys/socket.h>#include <netinet/in.h>#include <arpa/inet.h>#include <stdlib.h>#include <stdio.h>#include <errno.h>#include <string.h>#define
2021-12-23 15:41:14
1442
原创 8.14.1
#include <sys/types.h>#include <sys/socket.h>#include <netinet/in.h>#include <arpa/inet.h>#include <stdlib.h>#include <stdio.h>#include <errno.h>#include <string.h>#define portnumber 3333int main(
2021-12-23 15:40:21
676
原创 4.9.2
#include<time.h>#include<stdio.h>#include<sys/time.h>void func(){ int i,j,k; for(i=0;i<1000;i++) for(j=0;j<1000;j++) k++;}int main(){ /*time_val结构体中存着1970年元年到调用gettime函数的时间(秒数+小数点即毫秒*/ st...
2021-12-23 15:38:21
215
原创 4.9.1
/*编写一个程序,可以以字符串的形式显示本地时间。*/#include<time.h>#include<stdio.h>int main(){ time_t t; t=time(NULL);//取得日历形式的本地时间 char *s=ctime(&t); printf("%s\n",s); return 0;}/*ctime函数可以直接把日历时间转为本地时间形式的字符串,无需利用localtime函数先把日历时间转为本...
2021-12-23 15:37:52
289
原创 4.8.2
#include<stdio.h>#include<curses.h>int main(int argc,char *argv[]){ FILE *fp; char ch; fp=fopen(argv[1],"rw"); ch=fgetc(fp); while(ch!=EOF) { putchar(ch); ch=fgetc(fp);//fget函数在读取一个字符后光标自动后移 } ...
2021-12-23 15:36:29
101
原创 4.7.6
/*利用access函数判断文件输入的文件名是否存在*/#include<stdio.h>#include<stdlib.h>#include<unistd.h>int main(int argc,char *argv[]){ int ret=access(argv[1],F_OK); if(ret==0) printf("该文件存在"); else printf("该文件不存在!"); return 0;}...
2021-12-23 15:34:46
322
原创 4.7.3
#include<stdio.h>#include<stdlib.h>#include<unistd.h>#include<sys/types.h>#include<sys/stat.h>#include<fcntl.h>int main(int argc,char *argv[]){ char buff[100]="hello world!"; int fd=open(argv[1],O_RDWR,06...
2021-12-23 15:34:05
180
原创 4.7.2
/*以只读方式打开一个已有文件并从中读取20个字符并打印*/#include<stdio.h>#include<stdlib.h>#include<unistd.h>#include<sys/types.h>#include<sys/stat.h>#include<fcntl.h>int main(int argc,char *argv[]){ char buff[100]; int fd=open(...
2021-12-23 15:33:33
319
原创 7.7 7.5
#include<stdio.h>#include<pthread.h>static pthread_mutex_t testlock;pthread_t test;void *func(){ pthread_mutex_lock(&testlock); printf("FUNC LOCK!\n"); pthread_mutex_unlock(&testlock); }int main(){ pthread_...
2021-12-16 18:56:17
60
原创 7.4.41
#include <stdio.h>#include <stdlib.h>#include <unistd.h>#include <pthread.h>void * func0(void* arg){ char *s=(char*)arg; printf("clean_fun1:%s\r\n",s);}void * func00(void* arg){ int p=(int)arg;...
2021-12-16 18:03:58
39
原创 7.4.2 pthread
#include<stdio.h>#include<pthread.h>#include<stdlib.h>#include<unistd.h>void *func(){ printf("你没有机会了\n"); pthread_exit((void*)7);}int main(){ pthread_t t1; void *temp; pthread_create(&t1,NULL,func,N...
2021-12-16 18:03:20
37
原创 7.4.2 return
#include<stdio.h>#include<pthread.h>#include<stdlib.h>#include<unistd.h>void *func(){ printf("你没有机会了\n"); return(void*)8;}int main(){ pthread_t t1; void *temp; pthread_create(&t1,NULL,func,NULL);...
2021-12-16 18:02:48
34
原创 7.4.23
#include<stdio.h>#include<pthread.h>#include<semaphore.h>sem_t sem;int i=0;void *write(){ while(1){ printf("线程输入:"); scanf("%d",&i); sem_post(&sem); sleep(1);}}void main(){ pthread_t t1;...
2021-12-16 18:01:49
155
原创 7.4.22
#include<stdio.h>#include<pthread.h>/*前两个必须设置为全局变量*/static pthread_mutex_t testlock;pthread_t test;int i=0;void *func(){ pthread_mutex_lock(&testlock); printf("我是子进程\n"); while(i<20) printf("%d\n",i++); p...
2021-12-16 18:01:17
41
原创 7.4.21
#include<pthread.h>#include<stdio.h>void *func(){ printf("我是子进程\n"); sleep(1);}int main(){ pthread_t test; pthread_create(&test,NULL,func,NULL); pthread_join(test,NULL); sleep(1); printf("我是主进程\n"); r...
2021-12-16 17:59:56
30
原创 7.4.2 exit
#include<stdio.h>#include<pthread.h>#include<stdlib.h>#include<unistd.h>void *func(){ printf("你没有机会了\n"); exit(0);}int main(){ pthread_t t1; void *temp; pthread_create(&t1,NULL,func,NULL); pthre...
2021-12-16 17:58:51
34
原创 7.4.5
#include <stdio.h>#include <stdlib.h>#include <unistd.h>#include <pthread.h>void * func0(void* arg){ char *s=(char*)arg; printf("clean_fun1:%s\r\n",s);}void * func00(void* arg){ int p=(int)arg;...
2021-12-16 17:57:23
48
原创 7.4.4
#include <stdio.h>#include <stdlib.h>#include <unistd.h>#include <pthread.h>void * func0(void* arg){ char *s=(char*)arg; printf("clean_fun1:%s\r\n",s);}void * func00(void* arg){ int p=(int)arg; .
2021-12-16 17:56:01
193
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人