⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 test1.c

📁 unix下多进程编程实例
💻 C
字号:
#include <pthread.h>

typedef struct _song{
	int i;
	int j;
} SONG;

void* thread1();
void* thread2();
main()
{
        pthread_t       thd1,thd2;
        pthread_attr_t  thdattr1,thdattr2;
        int iLoop,thd;
		SONG sSong;

		sSong.i=1;
		sSong.j=2;
	thd=pthread_self();
	printf("thd0=%d\n",thd);		
        pthread_attr_init(&thdattr1);
        pthread_attr_init(&thdattr2);
        pthread_create(&thd1,&thdattr1,thread1,&sSong);
        printf("create thread 1 is %d\n",thd1);
        pthread_create(&thd2,&thdattr2,thread2,NULL);
        printf("create thread 2 is %d\n",thd2);
        for(iLoop=0;iLoop<10;iLoop++){
                printf("this is main %d\n",iLoop);
                sleep(3);
        }
}

void* thread1(SONG *sSong)
{
        int iLoop,thd;
        thd=pthread_self();
        printf("thd1=%d\n",thd);
	execlp("test2","test2",NULL);
}
void* thread2()
{
        int iLoop,thd;
	thd=pthread_self();
	printf("thd2=%d\n",thd);
        for(iLoop=0;iLoop<10;iLoop++){
                printf("this is thread 2\n");
                sleep(1);
        }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -