[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <59403595-9F9B-49C4-AB62-259DD2C40196@linux.alibaba.com>
Date: Fri, 23 Sep 2022 11:56:55 +0800
From: "cambda@...ux.alibaba.com" <cambda@...ux.alibaba.com>
To: "Eric W. Biederman" <ebiederm@...ssion.com>
Cc: linux-kernel@...r.kernel.org, linux-api@...r.kernel.org,
Xuan Zhuo <xuanzhuo@...ux.alibaba.com>,
Dust Li <dust.li@...ux.alibaba.com>,
Tony Lu <tonylu@...ux.alibaba.com>
Subject: Re: Syscall kill() can send signal to thread ID
> On Sep 22, 2022, at 23:33, Eric W. Biederman <ebiederm@...ssion.com> wrote:
>
> cambda@...ux.alibaba.com writes:
>
>> I found syscall kill() can send signal to a thread id, which is
>> not the TGID. But the Linux manual page kill(2) said:
>>
>> "The kill() system call can be used to send any signal to any
>> process group or process."
>>
>> And the Linux manual page tkill(2) said:
>>
>> "tgkill() sends the signal sig to the thread with the thread ID
>> tid in the thread group tgid. (By contrast, kill(2) can be used
>> to send a signal only to a process (i.e., thread group) as a
>> whole, and the signal will be delivered to an arbitrary thread
>> within that process.)"
>>
>> I don't know whether the meaning of this 'process' should be
>> the TGID? Because I found kill(tid, 0) will return ESRCH on FreeBSD,
>> while Linux sends signal to the thread group that the thread belongs
>> to.
>>
>> If this is as expected, should we add a notice to the Linux manual
>> page? Because it's a syscall and the pids not equal to tgid are not
>> listed under /proc. This may be a little confusing, I guess.
>
> How did you come across this? Were you just experimenting?
>
> I am wondering if you were tracking a bug, or a portability problem
> or something else. If the current behavior is causing problems in
> some way instead of just being a detail that no one really cares about
> either way it would be worth considering if we want to maintain the
> current behavior.
>
> Eric
I have found I can cd into /proc/tid, and the proc_pid_readdir()
uses next_tgid() to filter tid. Also the 'ps' command reads the
/proc dir to show processes. That's why I was confused with kill().
And yes, I'm tracking a bug. A service monitor, like systemd or
some watchdog, uses kill() to check if a pid is valid or not:
1. Store service pid into cache.
2. Check if pid in cache is valid by kill(pid, 0).
3. Check if pid in cache is the service to watch.
So if kill(pid, 0) returns success but no process info shows on 'ps'
command, the service monitor could be confused. The monitor could
check if pid is tid, but this means the odd behavior would be used
intentionally. And this workaround may be unsafe on other OS?
I'm agreed with you that this behavior shouldn't be removed, in case
some userspace applications use it now.
Regards,
Cambda
Powered by blists - more mailing lists