[PATCH] sched: clarify ptrace's effect on task_struct->parent

Ziran Zhang posted 1 patch 2 weeks, 1 day ago
There is a newer version of this series
include/linux/sched.h | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
[PATCH] sched: clarify ptrace's effect on task_struct->parent
Posted by Ziran Zhang 2 weeks, 1 day ago
The current comment for the parent field does not explain that it can be
temporarily replaced by the tracer when the task is being ptraced.

This can lead to confusion, so clarify the comment to document this
important behavior.

No functional change.

Signed-off-by: Ziran Zhang <zhangcoder@yeah.net>
---
 include/linux/sched.h | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/include/linux/sched.h b/include/linux/sched.h
index 705970d07..977859a63 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -1093,7 +1093,11 @@ struct task_struct {
 	/* Real parent process: */
 	struct task_struct __rcu	*real_parent;
 
-	/* Recipient of SIGCHLD, wait4() reports: */
+	/*
+	 * Recipient of SIGCHLD, wait4() reports. Normally the same as
+	 * real_parent, but temporarily replaced by the tracer while the
+	 * task is ptraced.
+	 */
 	struct task_struct __rcu	*parent;
 
 	/*
-- 
2.51.0
Re: [PATCH] sched: clarify ptrace's effect on task_struct->parent
Posted by Oleg Nesterov 2 weeks, 1 day ago
On 09/10, Ziran Zhang wrote:
> The current comment for the parent field does not explain that it can be
> temporarily replaced by the tracer when the task is being ptraced.
> 
> This can lead to confusion, so clarify the comment to document this
> important behavior.
> 
> No functional change.
> 
> Signed-off-by: Ziran Zhang <zhangcoder@yeah.net>
> ---
>  include/linux/sched.h | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/include/linux/sched.h b/include/linux/sched.h
> index 705970d07..977859a63 100644
> --- a/include/linux/sched.h
> +++ b/include/linux/sched.h
> @@ -1093,7 +1093,11 @@ struct task_struct {
>  	/* Real parent process: */
>  	struct task_struct __rcu	*real_parent;
>  
> -	/* Recipient of SIGCHLD, wait4() reports: */
> +	/*
> +	 * Recipient of SIGCHLD, wait4() reports. Normally the same as
> +	 * real_parent, but temporarily replaced by the tracer while the
> +	 * task is ptraced.
> +	 */
>  	struct task_struct __rcu	*parent;

Well. Not sure this comment needs to be updated...

Anyway, this looks like overdocumentation to me. Perhaps just

	/* Recipient of SIGCHLD, wait4() reports: ->real_parent or ptracer */

?

Oleg.
Re: [PATCH] sched: clarify ptrace's effect on task_struct->parent
Posted by Ziran Zhang 2 weeks, 1 day ago
On Thu, 10 Sep 2026 14:54:04 +0200, Oleg Nesterov <oleg@redhat.com> wrote:
> Well. Not sure this comment needs to be updated...
> 
> Anyway, this looks like overdocumentation to me. Perhaps just
> 
> 	/* Recipient of SIGCHLD, wait4() reports: ->real_parent or ptracer */
> 
> ?
> 
> Oleg.

Agreed, the long form is overdocumenting it. I'll send a v2 patch with your
suggestion.

Best,
Ziran Zhang
[PATCH v2] sched: clarify ptrace's effect on task_struct->parent
Posted by Ziran Zhang 2 weeks, 1 day ago
The current comment for the parent field does not explain that it can be
temporarily replaced by the tracer when the task is being ptraced.

This can lead to confusion, so clarify the comment to document this
important behavior.

No functional change.

Suggested-by: Oleg Nesterov <oleg@redhat.com>
Signed-off-by: Ziran Zhang <zhangcoder@yeah.net>
---
Changes in v2:
- Use Oleg's minimal wording suggestion to adjust comment.

 include/linux/sched.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/linux/sched.h b/include/linux/sched.h
index 705970d07..8aad8a8ef 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -1093,7 +1093,7 @@ struct task_struct {
 	/* Real parent process: */
 	struct task_struct __rcu	*real_parent;
 
-	/* Recipient of SIGCHLD, wait4() reports: */
+	/* Recipient of SIGCHLD, wait4() reports: ->real_parent or ptracer */
 	struct task_struct __rcu	*parent;
 
 	/*
-- 
2.51.0