Distributions
Ubuntu
Fedora
CentOS
中文资源站
网易开源镜像站
longtzw
V2EX  ›  Linux

clone 对 Linux 线程 ID 的影响

  •  
  •   longtzw · Jan 15, 2015 · 2900 views
    This topic created in 4162 days ago, the information mentioned may be changed or developed.

    之前一直通过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;
    

    }

    现在调用pthread_kill一直提示错误"no such process", 换回系统调用system又恢复正常。

    我把CLONE_VM标志去掉,运行也是正常的,难道CLONE_VM对线程由啥影响?

    No Comments Yet
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3484 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 00:19 · PVG 08:19 · LAX 17:19 · JFK 20:19
    ♥ Do have faith in what you're doing.