linux c 多进程多线程比较

多进程

#include 
#include 

int main(){
        pid_t pid;
        int result;
        pid = fork();
        if(pid <0)
        {
        }
        else if (pid == 0)
        {//子进程
                char my_cmd3[]="./gh www.baidu.com > lll"; 
                system(my_cmd3);

        }
        else
        {//父进程

        }

}
编译 

gcc -o testj testj.c

多线程

#include 
#include 
void thread(void)
{
	int i; 
		char my_cmd3[]="./gh www.baidu.com >> lll"; 
                system(my_cmd3);

}

int main(void)
{
	pthread_t id;
	int i,ret,j;
	for(j=0;j<3;j++)
	{
		ret=pthread_create(&id,NULL,(void *) thread,NULL);
		if(ret!=0)
		{
		printf ("Create pthread error!\n");
		return 1;
		}
		pthread_join(id,NULL);
	}
 
	printf("This is the main process.\n");
	
	return 0;
}


你可能感兴趣的:(多线程,linux,c,cmd,thread,null)