技术解析

clone 对 Linux 线程 ID 的影响
0
2021-07-14 11:19:52
idczone

之前一直通过pthread_kill向指定线程发送信号,但后来将系统调用system换成了如下的实现:

long ___system(const char *pcStr)
{

int status;
int pid;
char tmpstack[SYSTEM_STACKSIZE];
void **newstack;

newstack = (void **)(void *)(ULONG) (SYSTEM_STACKSIZE + tmpstack);
*--newstack = (void *)pcStr;

pid = clone(__system_proc, newstack,
            CLONE_VM | CLONE_FS | SIGCHLD, (void *)pcStr); 
if (pid < 0)
{       
    printf("clone() failed! errno = %d[%s]\n", errno, strerror(errno));
    return -1;
}

(void)waitpid(pid, &status, __WALL /*__WCLONE*/);

return status;



数据地带为您的网站提供全球顶级IDC资源