Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp532952rwb; Thu, 22 Sep 2022 23:52:35 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4Kkao0bvOaO5V/7BIIUo1JZxm8wFpVTQi7U9VgTvXPxtU5QoVc9EH0YcQRVy/MmcAwtj7r X-Received: by 2002:a17:903:2582:b0:176:9ba8:3c9f with SMTP id jb2-20020a170903258200b001769ba83c9fmr7078796plb.87.1663915955575; Thu, 22 Sep 2022 23:52:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663915955; cv=none; d=google.com; s=arc-20160816; b=ikr3q7iv5MwSEP9tyMul9g6/uq2jvqGPzXePewT75B+j5+fmI7Z6Wjne067XambQbg xXZ0ytMDl+rVx5Btd/2hLZoWEj8lNMqYndckQPms+OtLeerscPxGnktrW1XD0bjKeJHF 3ZnWx9KnvoJp1D0g7iT3V7CJHr3VAmKvxkh5qKxVM+VRDAB0vp06SkSGSH7ybbIAsWhx 07d25OqDGDJcrqDVu11cJ5QZCvhOovFIfMHX8aQBAIsVbIncubaNSoiEhfVY3iDjPdlu TGDosW4areh8mXpQ1LzjRZQV74WdZ2+bZmeF+7zgMsPePN4IJ/6AK4mSsPBZ0WZ5CVW9 sQNw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:to:references:message-id :content-transfer-encoding:cc:date:in-reply-to:from:subject :mime-version; bh=YCKbJlIzc4928XfzWQg/S4pIZ9sM98srK7bqY6selsM=; b=cwOerBTegEOKodE/xf5qrjZM5fRTMPVitO1tnk0UOmdYVJC6wMpTBCQ3Gx0kHmh8Um a2BCNwW1EtQpMZ8oWbpuFr1HdNxrKm7+xENbXnZCy1BnFH8i2jMH7aV+n+od/xoDKvIi bK6E5rIqBBubnxoe57Kv6epqAVyZNC3K/edld3p51KXL6KZnwr/jnXBDUVyh/nXF3BDF 3tLJO/hU/axbfIkFdiNk+0iuWniYWkuEC0SnQaUCubJNRP20tz7RVlCvP/d8NbaKrtQg Cr89hwBgibvRqyZHqfkhNLy58eVmRVkRWfjA8jEVnYnwAsjT+kXF6Od1IvVPDyiJdGD5 +8ww== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e13-20020a170903240d00b00175284c8e9dsi1997652plo.199.2022.09.22.23.52.24; Thu, 22 Sep 2022 23:52:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230210AbiIWGZM convert rfc822-to-8bit (ORCPT + 99 others); Fri, 23 Sep 2022 02:25:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44148 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230197AbiIWGZK (ORCPT ); Fri, 23 Sep 2022 02:25:10 -0400 Received: from out30-132.freemail.mail.aliyun.com (out30-132.freemail.mail.aliyun.com [115.124.30.132]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 93A7E9C23D; Thu, 22 Sep 2022 23:25:09 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R161e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046059;MF=cambda@linux.alibaba.com;NM=1;PH=DS;RN=7;SR=0;TI=SMTPD_---0VQVe2Tc_1663914306; Received: from smtpclient.apple(mailfrom:cambda@linux.alibaba.com fp:SMTPD_---0VQVe2Tc_1663914306) by smtp.aliyun-inc.com; Fri, 23 Sep 2022 14:25:06 +0800 Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3696.120.41.1.1\)) Subject: Re: Syscall kill() can send signal to thread ID From: "cambda@linux.alibaba.com" In-Reply-To: <87r102ejwo.fsf@oldenburg.str.redhat.com> Date: Fri, 23 Sep 2022 14:25:05 +0800 Cc: "Eric W. Biederman" , linux-kernel@vger.kernel.org, linux-api@vger.kernel.org, Xuan Zhuo , Dust Li , Tony Lu Content-Transfer-Encoding: 8BIT Message-Id: <0CC7D0E7-71C5-4DAC-8A01-F9E13659F864@linux.alibaba.com> References: <69E17223-F0CA-4A4C-AAD7-065D6E6266D9@linux.alibaba.com> <87pmfn5tu1.fsf@email.froward.int.ebiederm.org> <87r102ejwo.fsf@oldenburg.str.redhat.com> To: Florian Weimer X-Mailer: Apple Mail (2.3696.120.41.1.1) X-Spam-Status: No, score=-9.9 required=5.0 tests=BAYES_00, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2, SPF_HELO_NONE,SPF_PASS,UNPARSEABLE_RELAY,USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org > On Sep 23, 2022, at 13:31, Florian Weimer wrote: > > * Eric W. Biederman: > >> cambda@linux.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. >> >> This is as expected. >> >> The bit about is /proc is interesting. On linux try >> "cd /proc; cd tid" and see what happens. >> >> Using the thread id in kill(2) is used to select the process, and the >> delivery happens just the same as if the TGID had been used. >> >> It is one of those odd behaviors that we could potentially remove. It >> would require hunting through all of the userspace applications to see >> if something happens to depend upon that behavior. Unless it becomes >> expensive to maintain I don't expect we will ever do that. > > It would just replace one odd behavior by another because kill for the > TID of the main thread will still send the signal to the entire process > (because the TID is equal to the PID), but for the other threads, it > would just send it to the thread. So it would still be inconsistent. > > Thanks, > Florian 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? Regards, Cambda