c++小牛钱小白

c++中子线程函数中调用system或fork的实战应用??

在子线程函数里调用system或者fork出错??

#include <iostream>

#include <stdio.h>

#include <string.h>

#include <stdlib.h>

#include <unistd.h>

#include <pthread.h>

using namespace std;


void* task1(void *arg1)

{

printf("task1\n");

system("ls");

pthread_exit((void *)1);

}


int main()

{

int ret = 0;

void *p;

int p1 = 0;

pthread_t pid1;

pthread_create(&pid1, NULL, task1, NULL);

ret = pthread_join(pid1, &p);

printf("end main:pid1 is \n", ret);

    //cout << "Hello, world!" << endl;

    //return 0;

return 1;

}

// 编译时出错,提示undefined reference to `pthread_create';undefined reference to `pthread_join'??

评论
© c++小牛钱小白 | Powered by LOFTER