when is the system call set_tid_address used?

2019-05-20 08:19发布

i have been trying to undertand the system calls, and want to understand how set_tid_address works. bascially from what i have read is that it returns the pid of the program or process which is executed.

I have tested this with ls, however with some commands like uptime, top etc i dont see set_tid_address being used. Why is that?

2条回答
【Aperson】
2楼-- · 2019-05-20 08:49

The clone() syscall can take a CLONE_CHILD_CLEARTID flag, that the value at child_tidptr (another clone() argument) gets cleared and an associated futex signal a wake-up when the child thread exits. This is used to implement pthread_join() (the parent thread waits on the futex).

set_tid_address() allows to pthread_join() on the initial thread. More information in the following LKML threads:

[patch] threading fix, tid-2.5.47-A3
[patch] user-vm-unlock-2.5.31-A2

As to why some programs call set_tid_address() and others don't, the answer is easy. Programs linked (directly or indirectly) to libpthread call set_tid_address. ls is linked to librt, which is linked to libpthread, so it runs the initialization for NPTL.

查看更多
来,给爷笑一个
3楼-- · 2019-05-20 08:59

According to the Linux Programmer's Manual, set_tid_address is used to:

set pointer to thread ID

When it is finished, it returns the PID of the calling process. Unfortunately the manual is vague as to when you would actually want to use this system call.

In any case, why do you think that these commands are using set_tid_address?

查看更多
登录 后发表回答