public inbox for linux-api@vger.kernel.org
 help / color / mirror / Atom feed
From: "Eric W. Biederman" <ebiederm@xmission.com>
To: Cambda Zhu <cambda@linux.alibaba.com>
Cc: Florian Weimer <fweimer@redhat.com>,
	linux-kernel@vger.kernel.org, linux-api@vger.kernel.org,
	Xuan Zhuo <xuanzhuo@linux.alibaba.com>,
	Dust Li <dust.li@linux.alibaba.com>,
	Tony Lu <tonylu@linux.alibaba.com>
Subject: Re: Syscall kill() can send signal to thread ID
Date: Fri, 23 Sep 2022 16:15:17 -0500	[thread overview]
Message-ID: <87illd4wt6.fsf@email.froward.int.ebiederm.org> (raw)
In-Reply-To: <613994F7-054D-4992-A159-96D34B17BC7F@linux.alibaba.com> (Cambda Zhu's message of "Fri, 23 Sep 2022 16:40:15 +0800")

Cambda Zhu <cambda@linux.alibaba.com> writes:

>> On Sep 23, 2022, at 15:53, Florian Weimer <fweimer@redhat.com> wrote:
>> 
>>> I don't quite understand what you mean, sorry. But if kill() returns
>>> -ESRCH for tid which is not equal to tgid, kill() can only send signal
>>> to thread group via main thread id, that is what BSD did and manual
>>> said. It seems not odd?
>> 
>> It's still odd because there's one TID per process that's valid for
>> kill by accident.  That's all.

> As far as I know, there is no rule forbidding 'process ID'(TGID on Linux)
> equals to main thread ID, is it right?

There is an unfortunate guarantee that glibc depends upon that after
exec TGID == TID for the initial thread in a process.  I say unfortunate
because maintaining that guarantee when another thread in the process
calls exec is a bit painful.

> If one wants to send signal to a specific thread, tgkill() can do
> that. As far as I understand, the difference between kill() and
> tgkill() is whether the signal is set on shared_pending, whatever the
> ID is a process ID or a thread ID. For Linux, the main thread ID just
> equals to the process ID.

Correct.  kill and tgkill uses different signal queues.  Kill is global
to the destination process and tgkill is always thread local.

> So the meaning of kill(main_tid, sig) is sending signal to a process,
> of which the PID equals to the first argument. It's not odd, I think.

Yes, the oddity is the TGID and TID share the same value, nothing else.

Eric

  reply	other threads:[~2022-09-23 21:15 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-22  9:11 Syscall kill() can send signal to thread ID cambda
2022-09-22 15:09 ` Eric W. Biederman
2022-09-23  5:31   ` Florian Weimer
2022-09-23  6:25     ` cambda
2022-09-23  7:53       ` Florian Weimer
2022-09-23  8:40         ` Cambda Zhu
2022-09-23 21:15           ` Eric W. Biederman [this message]
2022-09-22 15:33 ` Eric W. Biederman
2022-09-23  3:56   ` cambda
2022-09-23 11:24     ` David Laight
2022-09-23 21:21     ` Eric W. Biederman
2022-09-24  3:16       ` Cambda Zhu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87illd4wt6.fsf@email.froward.int.ebiederm.org \
    --to=ebiederm@xmission.com \
    --cc=cambda@linux.alibaba.com \
    --cc=dust.li@linux.alibaba.com \
    --cc=fweimer@redhat.com \
    --cc=linux-api@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tonylu@linux.alibaba.com \
    --cc=xuanzhuo@linux.alibaba.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox