Reputation: 125
I created 3 thread using pthread_create
utility. I could send signal to thread using
kill -SIGUSR1 thread-id
.
I got thread id using ps -eLF
command ( LWP field ).
I am wondering:
Why we need kill?
How can I use kill command to send a signal to thread group id.? How do I find the group id ?
Upvotes: 3
Views: 5896
Reputation: 5231
The thread group identifier (TGID) is actually the task identifier of the main thread of the process. And the main thread's task identifier is the process identifier of the whole process. This is the value returned by getpid() from any thread in the same process. In other words, gettid() returns the same value as getpid() in the main thread.
With the ps
command, the thread group identifier is obtained with the tgid format specifier. With the following ps
command, we can see that the lines with pid = tgid = tid is the main thread of the processes:
$ ps -eLo pid,tgid,tid,comm
PID TGID TID COMMAND
890 890 890 rsyslogd <-- Main thread = thread group id
890 890 915 in:imuxsock
890 890 916 in:imklog
890 890 917 rs:main Q:Reg
891 891 891 snapd <-- Main thread = thread group id
891 891 934 snapd
891 891 935 snapd
891 891 936 snapd
891 891 937 snapd
891 891 938 snapd
891 891 1000 snapd
891 891 1006 snapd
891 891 1007 snapd
891 891 1009 snapd
891 891 1010 snapd
891 891 1042 snapd
891 891 1043 snapd
891 891 1062 snapd
891 891 1063 snapd
891 891 1064 snapd
891 891 1542 snapd
891 891 1544 snapd
[...]
Upvotes: 2
Reputation: 15110
You need kill
because that's the command to send signals. By default it will kill a process, but you can send other signals as you know.
You can use killall -s <signal number> <executable name>
to send a signal to all processes sharing the same process name (not number).
Upvotes: 1