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?
The
clone()
syscall can take aCLONE_CHILD_CLEARTID
flag, that the value atchild_tidptr
(anotherclone()
argument) gets cleared and an associated futex signal a wake-up when the child thread exits. This is used to implementpthread_join()
(the parent thread waits on the futex).set_tid_address()
allows topthread_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 callset_tid_address
.ls
is linked tolibrt
, which is linked tolibpthread
, so it runs the initialization for NPTL.According to the Linux Programmer's Manual, set_tid_address is used to:
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
?