···4455#include <linux/pid_types.h>66#include <linux/rculist.h>77+#include <linux/rcupdate.h>78#include <linux/refcount.h>99+#include <linux/sched.h>810#include <linux/wait.h>9111012/*···206204 } \207205 task = tg___; \208206 } while_each_pid_task(pid, type, task)207207+208208+static inline struct pid *task_pid(struct task_struct *task)209209+{210210+ return task->thread_pid;211211+}212212+213213+/*214214+ * the helpers to get the task's different pids as they are seen215215+ * from various namespaces216216+ *217217+ * task_xid_nr() : global id, i.e. the id seen from the init namespace;218218+ * task_xid_vnr() : virtual id, i.e. the id seen from the pid namespace of219219+ * current.220220+ * task_xid_nr_ns() : id seen from the ns specified;221221+ *222222+ * see also pid_nr() etc in include/linux/pid.h223223+ */224224+pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type, struct pid_namespace *ns);225225+226226+static inline pid_t task_pid_nr(struct task_struct *tsk)227227+{228228+ return tsk->pid;229229+}230230+231231+static inline pid_t task_pid_nr_ns(struct task_struct *tsk, struct pid_namespace *ns)232232+{233233+ return __task_pid_nr_ns(tsk, PIDTYPE_PID, ns);234234+}235235+236236+static inline pid_t task_pid_vnr(struct task_struct *tsk)237237+{238238+ return __task_pid_nr_ns(tsk, PIDTYPE_PID, NULL);239239+}240240+241241+242242+static inline pid_t task_tgid_nr(struct task_struct *tsk)243243+{244244+ return tsk->tgid;245245+}246246+247247+/**248248+ * pid_alive - check that a task structure is not stale249249+ * @p: Task structure to be checked.250250+ *251251+ * Test if a process is not yet dead (at most zombie state)252252+ * If pid_alive fails, then pointers within the task structure253253+ * can be stale and must not be dereferenced.254254+ *255255+ * Return: 1 if the process is alive. 0 otherwise.256256+ */257257+static inline int pid_alive(const struct task_struct *p)258258+{259259+ return p->thread_pid != NULL;260260+}261261+262262+static inline pid_t task_pgrp_nr_ns(struct task_struct *tsk, struct pid_namespace *ns)263263+{264264+ return __task_pid_nr_ns(tsk, PIDTYPE_PGID, ns);265265+}266266+267267+static inline pid_t task_pgrp_vnr(struct task_struct *tsk)268268+{269269+ return __task_pid_nr_ns(tsk, PIDTYPE_PGID, NULL);270270+}271271+272272+273273+static inline pid_t task_session_nr_ns(struct task_struct *tsk, struct pid_namespace *ns)274274+{275275+ return __task_pid_nr_ns(tsk, PIDTYPE_SID, ns);276276+}277277+278278+static inline pid_t task_session_vnr(struct task_struct *tsk)279279+{280280+ return __task_pid_nr_ns(tsk, PIDTYPE_SID, NULL);281281+}282282+283283+static inline pid_t task_tgid_nr_ns(struct task_struct *tsk, struct pid_namespace *ns)284284+{285285+ return __task_pid_nr_ns(tsk, PIDTYPE_TGID, ns);286286+}287287+288288+static inline pid_t task_tgid_vnr(struct task_struct *tsk)289289+{290290+ return __task_pid_nr_ns(tsk, PIDTYPE_TGID, NULL);291291+}292292+293293+static inline pid_t task_ppid_nr_ns(const struct task_struct *tsk, struct pid_namespace *ns)294294+{295295+ pid_t pid = 0;296296+297297+ rcu_read_lock();298298+ if (pid_alive(tsk))299299+ pid = task_tgid_nr_ns(rcu_dereference(tsk->real_parent), ns);300300+ rcu_read_unlock();301301+302302+ return pid;303303+}304304+305305+static inline pid_t task_ppid_nr(const struct task_struct *tsk)306306+{307307+ return task_ppid_nr_ns(tsk, &init_pid_ns);308308+}309309+310310+/* Obsolete, do not use: */311311+static inline pid_t task_pgrp_nr(struct task_struct *tsk)312312+{313313+ return task_pgrp_nr_ns(tsk, &init_pid_ns);314314+}315315+316316+/**317317+ * is_global_init - check if a task structure is init. Since init318318+ * is free to have sub-threads we need to check tgid.319319+ * @tsk: Task structure to be checked.320320+ *321321+ * Check if a task structure is the first user space task the kernel created.322322+ *323323+ * Return: 1 if the task structure is init. 0 otherwise.324324+ */325325+static inline int is_global_init(struct task_struct *tsk)326326+{327327+ return task_tgid_nr(tsk) == 1;328328+}329329+209330#endif /* _LINUX_PID_H */
-122
include/linux/sched.h
···15611561 */15621562};1563156315641564-static inline struct pid *task_pid(struct task_struct *task)15651565-{15661566- return task->thread_pid;15671567-}15681568-15691569-/*15701570- * the helpers to get the task's different pids as they are seen15711571- * from various namespaces15721572- *15731573- * task_xid_nr() : global id, i.e. the id seen from the init namespace;15741574- * task_xid_vnr() : virtual id, i.e. the id seen from the pid namespace of15751575- * current.15761576- * task_xid_nr_ns() : id seen from the ns specified;15771577- *15781578- * see also pid_nr() etc in include/linux/pid.h15791579- */15801580-pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type, struct pid_namespace *ns);15811581-15821582-static inline pid_t task_pid_nr(struct task_struct *tsk)15831583-{15841584- return tsk->pid;15851585-}15861586-15871587-static inline pid_t task_pid_nr_ns(struct task_struct *tsk, struct pid_namespace *ns)15881588-{15891589- return __task_pid_nr_ns(tsk, PIDTYPE_PID, ns);15901590-}15911591-15921592-static inline pid_t task_pid_vnr(struct task_struct *tsk)15931593-{15941594- return __task_pid_nr_ns(tsk, PIDTYPE_PID, NULL);15951595-}15961596-15971597-15981598-static inline pid_t task_tgid_nr(struct task_struct *tsk)15991599-{16001600- return tsk->tgid;16011601-}16021602-16031603-/**16041604- * pid_alive - check that a task structure is not stale16051605- * @p: Task structure to be checked.16061606- *16071607- * Test if a process is not yet dead (at most zombie state)16081608- * If pid_alive fails, then pointers within the task structure16091609- * can be stale and must not be dereferenced.16101610- *16111611- * Return: 1 if the process is alive. 0 otherwise.16121612- */16131613-static inline int pid_alive(const struct task_struct *p)16141614-{16151615- return p->thread_pid != NULL;16161616-}16171617-16181618-static inline pid_t task_pgrp_nr_ns(struct task_struct *tsk, struct pid_namespace *ns)16191619-{16201620- return __task_pid_nr_ns(tsk, PIDTYPE_PGID, ns);16211621-}16221622-16231623-static inline pid_t task_pgrp_vnr(struct task_struct *tsk)16241624-{16251625- return __task_pid_nr_ns(tsk, PIDTYPE_PGID, NULL);16261626-}16271627-16281628-16291629-static inline pid_t task_session_nr_ns(struct task_struct *tsk, struct pid_namespace *ns)16301630-{16311631- return __task_pid_nr_ns(tsk, PIDTYPE_SID, ns);16321632-}16331633-16341634-static inline pid_t task_session_vnr(struct task_struct *tsk)16351635-{16361636- return __task_pid_nr_ns(tsk, PIDTYPE_SID, NULL);16371637-}16381638-16391639-static inline pid_t task_tgid_nr_ns(struct task_struct *tsk, struct pid_namespace *ns)16401640-{16411641- return __task_pid_nr_ns(tsk, PIDTYPE_TGID, ns);16421642-}16431643-16441644-static inline pid_t task_tgid_vnr(struct task_struct *tsk)16451645-{16461646- return __task_pid_nr_ns(tsk, PIDTYPE_TGID, NULL);16471647-}16481648-16491649-static inline pid_t task_ppid_nr_ns(const struct task_struct *tsk, struct pid_namespace *ns)16501650-{16511651- pid_t pid = 0;16521652-16531653- rcu_read_lock();16541654- if (pid_alive(tsk))16551655- pid = task_tgid_nr_ns(rcu_dereference(tsk->real_parent), ns);16561656- rcu_read_unlock();16571657-16581658- return pid;16591659-}16601660-16611661-static inline pid_t task_ppid_nr(const struct task_struct *tsk)16621662-{16631663- return task_ppid_nr_ns(tsk, &init_pid_ns);16641664-}16651665-16661666-/* Obsolete, do not use: */16671667-static inline pid_t task_pgrp_nr(struct task_struct *tsk)16681668-{16691669- return task_pgrp_nr_ns(tsk, &init_pid_ns);16701670-}16711671-16721564#define TASK_REPORT_IDLE (TASK_REPORT + 1)16731565#define TASK_REPORT_MAX (TASK_REPORT_IDLE << 1)16741566···16021710static inline char task_state_to_char(struct task_struct *tsk)16031711{16041712 return task_index_to_char(task_state_index(tsk));16051605-}16061606-16071607-/**16081608- * is_global_init - check if a task structure is init. Since init16091609- * is free to have sub-threads we need to check tgid.16101610- * @tsk: Task structure to be checked.16111611- *16121612- * Check if a task structure is the first user space task the kernel created.16131613- *16141614- * Return: 1 if the task structure is init. 0 otherwise.16151615- */16161616-static inline int is_global_init(struct task_struct *tsk)16171617-{16181618- return task_tgid_nr(tsk) == 1;16191713}1620171416211715extern struct pid *cad_pid;
···1414#include <linux/unistd.h>1515#include <linux/err.h>1616#include <linux/ipc_namespace.h>1717+#include <linux/pid.h>17181819/*1920 * The IPC ID contains 2 separate numbers - index and sequence number.