Mercurial > hg > Members > nobuyasu > test
changeset 7:6b57e23a26cb
add event-driven apache
author | nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 31 May 2011 18:49:41 +0900 |
parents | e7f9f20d016b |
children | 515c780e1c13 |
files | multi/#mt.c# multi/.#mt.c multi/Makefile multi/mp multi/mp.c multi/mp.o multi/mt multi/mt.c multi/mt.o |
diffstat | 9 files changed, 185 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/multi/#mt.c# Tue May 31 18:49:41 2011 +0900 @@ -0,0 +1,55 @@ +#include <stdio.h> +#include <sys/types.h> +#include <pthread.h> + +void *counter(void *arg) +{ + int i; + pid_t pid; + pthread_t thread_id; + + pid=getpid(); + thread_id=pthread_self(); + + for(i=0;i<10;i++){ + sleep(1); + printf("[%d][%d]%d\n",pid,thread_id,i); + } + + return(arg); +} + +void main() +{ + pid_t p_pid; + pthread_t thread_id1,thread_id2; + int status; + void *result; + + p_pid=getpid(); + + printf("[%d]start\n",p_pid); + + status=pthread_create(&thread_id1,NULL,counter,(void *)NULL); + if(status!=0){ + fprintf(stderr,"pthread_create : %s",strerror(status)); + } + else{ + printf("[%d]thread_id1=%d\n",p_pid,thread_id1); + } + + status=pthread_create(&thread_id2,NULL,counter,(void *)NULL); + if(status!=0){ + fprintf(stderr,"pthread_create : %s",strerror(status)); + } + else{ + printf("[%d]thread_id2=%d\n",p_pid,thread_id2); + } + + pthread_join(thread_id1,&result); + printf("[%d]thread_id1 = %d end\n",p_pid,thread_id1); + pthread_join(thread_id2,&result); + printf("[%d]thread_id2 = %d end\n",p_pid,thread_id2); + + printf("[%d]end\n",p_pid); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/multi/.#mt.c Tue May 31 18:49:41 2011 +0900 @@ -0,0 +1,1 @@ +aotokage@dimolto.cr.ie.u-ryukyu.ac.jp.18985 \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/multi/Makefile Tue May 31 18:49:41 2011 +0900 @@ -0,0 +1,16 @@ +CC=gcc +CFLAGS=-g -O0 + +all: mp mt + +mp.o: mp.c +mt.o: mt.c + +mp: mp.o + $(CC) $(CFLAGS) -o $@ $^ + +mt: mt.o + $(CC) $(CFLAGS) -o $@ $^ + +clean: + rm -rf *.o mp mt
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/multi/mp.c Tue May 31 18:49:41 2011 +0900 @@ -0,0 +1,58 @@ +#include <stdio.h> +#include <sys/types.h> +#include <sys/wait.h> + +void counter() +{ + int i; + pid_t pid; + + pid=getpid(); + + for(i=0;i<10;i++){ + sleep(1); + printf("[%d]%d\n",pid,i); + } + + return; +} + +void main() +{ + pid_t p_pid,pid; + + p_pid=getpid(); + + printf("[%d]start\n",p_pid); + + switch(pid=fork()){ + case 0: /* child */ + counter(); + exit(0); + case -1: + perror("fork"); + break; + default: /* parent */ + printf("[%d]child pid = %d\n",p_pid,pid); + break; + } + + switch(pid=fork()){ + case 0: /* child */ + counter(); + exit(0); + case -1: + perror("fork"); + break; + default: /* parent */ + printf("[%d]child pid = %d\n",p_pid,pid); + break; + } + + pid=wait(0); + printf("[%d]pid = %d end\n",p_pid,pid); + pid=wait(0); + printf("[%d]pid = %d end\n",p_pid,pid); + + printf("[%d]end\n",p_pid); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/multi/mt.c Tue May 31 18:49:41 2011 +0900 @@ -0,0 +1,55 @@ +#include <stdio.h> +#include <sys/types.h> +#include <pthread.h> + +void *counter(void *arg) +{ + int i; + pid_t pid; + pthread_t thread_id; + + pid=getpid(); + thread_id=pthread_self(); + + for(i=0;i<10;i++){ + sleep(1); + printf("[%d][%d]%d\n",pid,thread_id,i); + } + + return(arg); +} + +void main() +{ + pid_t p_pid; + pthread_t thread_id1,thread_id2; + int status; + void *result; + + p_pid=getpid(); + + printf("[%d]start\n",p_pid); + + status=pthread_create(&thread_id1,NULL,counter,(void *)NULL); + if(status!=0){ + fprintf(stderr,"pthread_create : %s",strerror(status)); + } + else{ + printf("[%d]thread_id1=%d\n",p_pid,thread_id1); + } + + status=pthread_create(&thread_id2,NULL,counter,(void *)NULL); + if(status!=0){ + fprintf(stderr,"pthread_create : %s",strerror(status)); + } + else{ + printf("[%d]thread_id2=%d\n",p_pid,thread_id2); + } + + pthread_join(thread_id1,&result); + printf("[%d]thread_id1 = %d end\n",p_pid,thread_id1); + pthread_join(thread_id2,&result); + printf("[%d]thread_id2 = %d end\n",p_pid,thread_id2); + + printf("[%d]end\n",p_pid); +}