1
私は以下の短いプログラムを持っています、私は "クローン"関数が実際にどのように機能するかを知ろうとしました。linux clone()関数は、奇妙なコンパイルエラーにつながります。なぜですか?
#include<stdio.h>
#include<sched.h>
#include<unistd.h>
#include<sys/types.h>
extern int errno;
int f(void*arg)
{
pid_t pid=getpid();
printf("child pid=%d\n",pid);
}
char buf[1024];
int main()
{
int ret=clone(f,buf,CLONE_VM|CLONE_VFORK,NULL);
if(ret==-1){
printf("%d\n",errno);
return 1;
}
printf("father pid=%d\n",getpid());
return 0;
}
グラム++ 4.1.2は、それをコンパイルし、言う:
$g++ testClone.cpp
/usr/bin/ld: errno: TLS definition in /lib64/libc.so.6 section .tbss mismatches non-TLS reference in /tmp/ccihZbuv.o
/lib64/libc.so.6: could not read symbols: Bad value
collect2: ld returned 1 exit status
は、私もどちらかのコンパイルされません
g++ testClone.cpp -lpthread
を試してみました。どうして?