File tree Expand file tree Collapse file tree 2 files changed +37
-0
lines changed Expand file tree Collapse file tree 2 files changed +37
-0
lines changed Original file line number Diff line number Diff line change @@ -78,6 +78,7 @@ struct file;
78
78
79
79
extern struct pid * pidfd_pid (const struct file * file );
80
80
struct pid * pidfd_get_pid (unsigned int fd , unsigned int * flags );
81
+ struct task_struct * pidfd_get_task (int pidfd , unsigned int * flags );
81
82
int pidfd_create (struct pid * pid , unsigned int flags );
82
83
83
84
static inline struct pid * get_pid (struct pid * pid )
Original file line number Diff line number Diff line change @@ -539,6 +539,42 @@ struct pid *pidfd_get_pid(unsigned int fd, unsigned int *flags)
539
539
return pid ;
540
540
}
541
541
542
+ /**
543
+ * pidfd_get_task() - Get the task associated with a pidfd
544
+ *
545
+ * @pidfd: pidfd for which to get the task
546
+ * @flags: flags associated with this pidfd
547
+ *
548
+ * Return the task associated with @pidfd. The function takes a reference on
549
+ * the returned task. The caller is responsible for releasing that reference.
550
+ *
551
+ * Currently, the process identified by @pidfd is always a thread-group leader.
552
+ * This restriction currently exists for all aspects of pidfds including pidfd
553
+ * creation (CLONE_PIDFD cannot be used with CLONE_THREAD) and pidfd polling
554
+ * (only supports thread group leaders).
555
+ *
556
+ * Return: On success, the task_struct associated with the pidfd.
557
+ * On error, a negative errno number will be returned.
558
+ */
559
+ struct task_struct * pidfd_get_task (int pidfd , unsigned int * flags )
560
+ {
561
+ unsigned int f_flags ;
562
+ struct pid * pid ;
563
+ struct task_struct * task ;
564
+
565
+ pid = pidfd_get_pid (pidfd , & f_flags );
566
+ if (IS_ERR (pid ))
567
+ return ERR_CAST (pid );
568
+
569
+ task = get_pid_task (pid , PIDTYPE_TGID );
570
+ put_pid (pid );
571
+ if (!task )
572
+ return ERR_PTR (- ESRCH );
573
+
574
+ * flags = f_flags ;
575
+ return task ;
576
+ }
577
+
542
578
/**
543
579
* pidfd_create() - Create a new pid file descriptor.
544
580
*
You can’t perform that action at this time.
0 commit comments