提交 e916287f 编写于 作者: H hypo

homework 2_3

上级 df028c4e
#include <stdio.h>
#include <unistd.h>
/*
| | `-1_topology_3
| | |-1_topology_3
| | | |-1_topology_3
| | | | |-1_topology_3
| | | | `-1_topology_3
| | | `-1_topology_3
| | | |-1_topology_3
| | | `-1_topology_3
| | `-1_topology_3
| | |-1_topology_3
| | | |-1_topology_3
| | | `-1_topology_3
| | `-1_topology_3
| | |-1_topology_3
| | `-1_topology_3
| | |-grep --color=auto 1_topology_3
*/
void btree_fork(num)
{
num--;
if (num != -1)
{
int pid = fork();
if(pid == -1)
int j = 0;
for (j = 0; j < 2; ++j)
{
printf("error!\n");
}
else if(pid ==0)
{
printf("This is the child process %d!\n",num);
recursive_fork(num);
getchar();
}
int pid = fork();
if(pid == -1)
{
printf("error!\n");
}
else if(pid ==0)
{
printf("This is the child process %d_%d\n",j);
btree_fork(num);
getchar();
}
}
}
}
int main(int argc, char ** argv )
{
int i = 0;
recursive_fork(10);
btree_fork(3);
{
printf("This is the parent process!\n");
getchar();
......
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
void thread(void)
{
// int i = 0;
printf("This is a pthread. address is %p\n", &thread);
sleep(10);
}
int main(void)
{
pthread_t id[10];
int i,ret;
for(i=0;i<10;i++)
{
ret=pthread_create(&id[i],NULL,(void *) thread,NULL);
if(ret!=0)
{
printf ("Create pthread error!\n");
exit (1);
}
}
printf("This is the main process.address is %p\n", &main);
for(i=0;i<10;i++)
{
pthread_join(id[i],NULL);
}
return (0);
}
\ No newline at end of file
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
void thread(void)
{
printf("This is a pthread.\n");
sleep(10);
}
int main(void)
{
pthread_t id[100];
int i,ret;
for(i=0;i<100;i++)
{
ret=pthread_create(&id[i],NULL,(void *) thread,NULL);
if(ret!=0)
{
printf ("Create pthread error!\n");
exit (1);
}
}
printf("This is the main process.\n");
for(i=0;i<100;i++)
{
pthread_join(id[i],NULL);
}
return (0);
}
\ No newline at end of file
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
void thread(void)
{
printf("This is a pthread.\n");
sleep(10);
}
int main(void)
{
pthread_t id;
int i,ret;
ret=pthread_create(&id,NULL,(void *) thread,NULL);
if(ret!=0)
{
printf ("Create pthread error!\n");
exit (1);
}
printf("This is the main process.\n");
pthread_join(id,NULL);
return (0);
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册