task_struct结构体查找

网上有很多解析task_struct结构体的文章,可是都没有说这个结构体到底在哪里?

这个结构体位于头文件 shced.h

cd /
find -name sched.h

显示结果如下

这里写图片描述

注意只有 位于内核中的include 才是正确的。
/usr/src/kernels/2.6.32-431.el6.i686/include/linux/sched.h

struct task_struct {volatile long state;    /* -1 unrunnable, 0 runnable, >0 stopped */void *stack;atomic_t usage;unsigned int flags; /* per process flags, defined below */unsigned int ptrace;int lock_depth;     /* BKL lock depth */#ifdef CONFIG_SMP
#ifdef __ARCH_WANT_UNLOCKED_CTXSWint oncpu;
#endif
#endifint prio, static_prio, normal_prio;unsigned int rt_priority;const struct sched_class *sched_class;struct sched_entity se;struct sched_rt_entity rt;#ifdef CONFIG_PREEMPT_NOTIFIERS/* list of struct preempt_notifier: */struct hlist_head preempt_notifiers;
#endif/** fpu_counter contains the number of consecutive context switches* that the FPU is used. If this is over a threshold, the lazy fpu* saving becomes unlazy to save the trap. This is an unsigned char* so that after 256 times the counter wraps and the behavior turns* lazy again; this to deal with bursty apps that only use FPU for* a short time*/unsigned char fpu_counter;
#ifdef CONFIG_BLK_DEV_IO_TRACEunsigned int btrace_seq;
#endifunsigned int policy;cpumask_t cpus_allowed;#ifdef CONFIG_TREE_PREEMPT_RCUint rcu_read_lock_nesting;char rcu_read_unlock_special;struct rcu_node *rcu_blocked_node;struct list_head rcu_node_entry;
#endif /* #ifdef CONFIG_TREE_PREEMPT_RCU */#if defined(CONFIG_SCHEDSTATS) || defined(CONFIG_TASK_DELAY_ACCT)struct sched_info sched_info;
#endifstruct list_head tasks;struct plist_node pushable_tasks;struct mm_struct *mm, *active_mm;/* task state */int exit_state;int exit_code, exit_signal;int pdeath_signal;  /*  The signal sent when the parent dies  *//* ??? */unsigned int personality;unsigned did_exec:1;unsigned in_execve:1;   /* Tell the LSMs that the process is doing an* execve */unsigned in_iowait:1;/* Revert to default priority/policy when forking */unsigned sched_reset_on_fork:1;pid_t pid;进程的标识符pid_t tgid;//线程组标识符#ifdef CONFIG_CC_STACKPROTECTOR/* Canary value for the -fstack-protector gcc feature */unsigned long stack_canary;
#endif/** pointers to (original) parent process, youngest child, younger sibling,* older sibling, respectively.  (p->father can be replaced with* p->real_parent->pid)*/struct task_struct *real_parent; /* real parent process */struct task_struct *parent; /* recipient of SIGCHLD, wait4() reports *//** children/sibling forms the list of my natural children*/struct list_head children;  /* list of my children */struct list_head sibling;   /* linkage in my parent's children list */struct task_struct *group_leader;   /* threadgroup leader *//** ptraced is the list of tasks this task is using ptrace on.* This includes both natural children and PTRACE_ATTACH targets.* p->ptrace_entry is p's link on the p->parent->ptraced list.*/struct list_head ptraced;struct list_head ptrace_entry;/* PID/PID hash table linkage. */struct pid_link pids[PIDTYPE_MAX];struct list_head thread_group;struct completion *vfork_done;      /* for vfork() */int __user *set_child_tid;      /* CLONE_CHILD_SETTID */int __user *clear_child_tid;        /* CLONE_CHILD_CLEARTID */cputime_t utime, stime, utimescaled, stimescaled;cputime_t gtime;cputime_t prev_utime, prev_stime;unsigned long nvcsw, nivcsw; /* context switch counts */struct timespec start_time;         /* monotonic time */struct timespec real_start_time;    /* boot based time */
/* mm fault and swap info: this can arguably be seen as either mm-specific or thread-    specific */unsigned long min_flt, maj_flt;struct task_cputime cputime_expires;struct list_head cpu_timers[3];/* process credentials */const struct cred *real_cred;   /* objective and real subjective task* credentials (COW) */const struct cred *cred;    /* effective (overridable) subjective task* credentials (COW) */struct mutex cred_guard_mutex;  /* guard against foreign influences on* credential calculations* (notably. ptrace) */struct cred *replacement_session_keyring; /* for KEYCTL_SESSION_TO_PARENT */char comm[TASK_COMM_LEN]; /* executable name excluding path- access with [gs]et_task_comm (which lockit with task_lock())- initialized normally by setup_new_exec */
/* file system info */int link_count, total_link_count;
#ifdef CONFIG_SYSVIPC
/* ipc stuff */struct sysv_sem sysvsem;
#endif
#ifdef CONFIG_DETECT_HUNG_TASK
/* hung task detection */unsigned long last_switch_count;
#endif
/* CPU-specific state of this task */struct thread_struct thread;
/* filesystem information */struct fs_struct *fs;
/* open file information */struct files_struct *files;
/* namespaces */struct nsproxy *nsproxy;
/* signal handlers */struct signal_struct *signal;struct sighand_struct *sighand;sigset_t blocked, real_blocked;sigset_t saved_sigmask; /* restored if set_restore_sigmask() was used */struct sigpending pending;unsigned long sas_ss_sp;size_t sas_ss_size;int (*notifier)(void *priv);void *notifier_data;sigset_t *notifier_mask;struct audit_context *audit_context;
#ifdef CONFIG_AUDITSYSCALLuid_t loginuid;unsigned int sessionid;
#endifseccomp_t seccomp;#ifdef CONFIG_UTRACEstruct utrace *utrace;unsigned long utrace_flags;
#endif/* Thread group tracking */u32 parent_exec_id;u32 self_exec_id;
/* Protection of (de-)allocation: mm, files, fs, tty, keyrings, mems_allowed,* mempolicy */spinlock_t alloc_lock;#ifdef CONFIG_GENERIC_HARDIRQS/* IRQ handler threads */struct irqaction *irqaction;
#endif/* Protection of the PI data structures: */spinlock_t pi_lock;#ifdef CONFIG_RT_MUTEXES/* PI waiters blocked on a rt_mutex held by this task */struct plist_head pi_waiters;/* Deadlock detection and priority inheritance handling */struct rt_mutex_waiter *pi_blocked_on;
#endif#ifdef CONFIG_DEBUG_MUTEXES/* mutex deadlock detection */struct mutex_waiter *blocked_on;
#endif
#ifdef CONFIG_TRACE_IRQFLAGSunsigned int irq_events;int hardirqs_enabled;unsigned long hardirq_enable_ip;unsigned int hardirq_enable_event;unsigned long hardirq_disable_ip;unsigned int hardirq_disable_event;int softirqs_enabled;unsigned long softirq_disable_ip;unsigned int softirq_disable_event;unsigned long softirq_enable_ip;unsigned int softirq_enable_event;int hardirq_context;int softirq_context;
#endif
#ifdef CONFIG_LOCKDEP
# define MAX_LOCK_DEPTH 48ULu64 curr_chain_key;int lockdep_depth;unsigned int lockdep_recursion;struct held_lock held_locks[MAX_LOCK_DEPTH];gfp_t lockdep_reclaim_gfp;
#endif/* journalling filesystem info */void *journal_info;/* stacked block device info */struct bio *bio_list, **bio_tail;/* VM state */struct reclaim_state *reclaim_state;struct backing_dev_info *backing_dev_info;struct io_context *io_context;unsigned long ptrace_message;siginfo_t *last_siginfo; /* For ptrace use.  */struct task_io_accounting ioac;
#if defined(CONFIG_TASK_XACCT)u64 acct_rss_mem1;  /* accumulated rss usage */u64 acct_vm_mem1;   /* accumulated virtual memory usage */cputime_t acct_timexpd; /* stime + utime since last update */
#endif
#ifdef CONFIG_CPUSETSnodemask_t mems_allowed;    /* Protected by alloc_lock */
#ifndef __GENKSYMS__/** This does not change the size of the struct_task(2+2+4=4+4)* so the offsets of the remaining fields are unchanged and * therefore the kABI is preserved.  Only the kernel uses* cpuset_mem_spread_rotor and cpuset_slab_spread_rotor so* it is safe to change it to use shorts instead of ints.*/   unsigned short cpuset_mem_spread_rotor;unsigned short cpuset_slab_spread_rotor;int mems_allowed_change_disable;
#elseint cpuset_mem_spread_rotor;int cpuset_slab_spread_rotor;
#endif
#endif
#ifdef CONFIG_CGROUPS/* Control Group info protected by css_set_lock */struct css_set *cgroups;/* cg_list protected by css_set_lock and tsk->alloc_lock */struct list_head cg_list;
#endif
#ifdef CONFIG_FUTEXstruct robust_list_head __user *robust_list;
#ifdef CONFIG_COMPATstruct compat_robust_list_head __user *compat_robust_list;
#endifstruct list_head pi_state_list;struct futex_pi_state *pi_state_cache;
#endif
#ifdef CONFIG_PERF_EVENTS
#ifndef __GENKSYMS__void * __reserved_perf__;
#elsestruct perf_event_context *perf_event_ctxp;
#endifstruct mutex perf_event_mutex;struct list_head perf_event_list;
#endif
#ifdef CONFIG_NUMAstruct mempolicy *mempolicy;    /* Protected by alloc_lock */short il_next;
#endifatomic_t fs_excl;   /* holding fs exclusive resources */struct rcu_head rcu;/** cache last used pipe for splice*/struct pipe_inode_info *splice_pipe;
#ifdef  CONFIG_TASK_DELAY_ACCTstruct task_delay_info *delays;
#endif
#ifdef CONFIG_FAULT_INJECTIONint make_it_fail;
#endifstruct prop_local_single dirties;
#ifdef CONFIG_LATENCYTOPint latency_record_count;struct latency_record latency_record[LT_SAVECOUNT];
#endif/** time slack values; these are used to round up poll() and* select() etc timeout values. These are in nanoseconds.*/unsigned long timer_slack_ns;unsigned long default_timer_slack_ns;struct list_head    *scm_work_list;
#ifdef CONFIG_FUNCTION_GRAPH_TRACER/* Index of current stored adress in ret_stack */int curr_ret_stack;/* Stack of return addresses for return function tracing */struct ftrace_ret_stack *ret_stack;/* time stamp for last schedule */unsigned long long ftrace_timestamp;/** Number of functions that haven't been traced* because of depth overrun.*/atomic_t trace_overrun;/* Pause for the tracing */atomic_t tracing_graph_pause;
#endif
#ifdef CONFIG_TRACING/* state flags for use by tracers */unsigned long trace;/* bitmask of trace recursion */unsigned long trace_recursion;
#endif /* CONFIG_TRACING *//* reserved for Red Hat */unsigned long rh_reserved[2];
#ifndef __GENKSYMS__struct perf_event_context *perf_event_ctxp[perf_nr_task_contexts];
#ifdef CONFIG_CGROUP_MEM_RES_CTLR /* memcg uses this to do batch job */struct memcg_batch_info {int do_batch;   /* incremented when batch uncharge started */struct mem_cgroup *memcg; /* target memcg of uncharge */unsigned long bytes;        /* uncharged usage */unsigned long memsw_bytes; /* uncharged mem+swap usage */} memcg_batch;
#endif
#endif
};

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/382753.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

闹钟函数alarm()的解释与实践

alarm 定义 也称为闹钟函数,它可以在进程中设置一个定时器,当定时器指定的时间到时,它向进程发送SIGALRM信号。可以设置忽略或者不捕获此信号,如果采用默认方式其动作是终止调用该alarm函数的进程。 #include "head.h&quo…

Linux下如何设置权限让用户只删除自己的文件(粘滞位)

之前我们知道如何针对用户和用户组来设置文件权限。通常是用三个八进制来设置权限的,这里我要说的是,其实是由四个八进制表示的。其中第一个八进制我们通常是忽略的。第二个到第四个是对应于SUID,SGID,sticky-bit。 SUID:设置了SUID 位的文件…

Vim简单配置

vim配置: (在Centos6.5下配置vim) 1.找到用户的主工作目录,ls看是否有.vimrc文件,有的话打开即可。没有的话自己touch一个。vim进入.vimrc中: set nu 设置行数 colorscheme desert syntax enabl…

[WPS笔试题]实现栈的push,pop,max且时间复杂度为O(1)

今天做了一下WPS的笔试题,遇到了一道关于栈的题,觉得挺有意思的,就写篇博客分享一下吧~~ 题目要求:要求实现栈的数据结构,在该类型中实现一个能够得到栈的最大元素的max函数,在该栈中,调用max,…

[剑指Offer]替换空格

今天看题的时候,遇到一个替换空格的题目,分析一下哈。 题目要求:把字符串中的每个空格替换成“%20”。例如输入“we are happy”,则输出“we%20are%20happy”。 解题思路:我们首先想到的是:移位思想。遇到…

C语言关键字 ISO/ANSI C90 C99 C11

面试考点 https://blog.csdn.net/csdn_kou/article/details/81113215 * 有的常用的我们都不知道是关键字,比如sizeof.这是面试中的考点,要注意。 * 同时当回答C语言中有多少关键字时,要回答前题条件,时针对哪一个版本

关于sudo

之前,我们使用sudo的时候,是因为其用户本身具有root权限,所以可以sudo后执行相关操作,但是对于普通用户来说,它是既不具有sudo权限,又不在sudo用户组中,那么我们来研究一下如何将新创建的用户添…

Bash入门

Bash简介: Bash(GNU Bourne-Again Shell)是一个为GNU计划编写的Unix shell,它是许多Linux平台默认使用的shell。 shell是一个命令解释器,是介于操作系统内核与用户之间的一个绝缘层。准确地说,它也是能力…

线程之售票系统pthread_mutex,_lock,_unlock

先看一下这篇文章 https://blog.csdn.net/csdn_kou/article/details/81148268 四个人同时买票票,引出线程 #include "head.h" int ticket 100; void * route(void *arg) {char *id (char *)arg;while(1){if(ticket>0){usleep(1000);printf("…

Bash基本语法

1. 变量赋值 a375 hello$a 这里需要注意的是,等号两边不能有空格 还有一个例子是这样的 例1: 结果为: 关于上述,主要有如下几点: $hello和${hello}是一样的,在bash中如果遇到空格,tab键时&a…

关于fd和fp(fd:file descirptor fp:file pointor)

通常,我们在输入数据或输出数据的设备为键盘或者显示器。当然,我们比较熟悉的输入输出,可能就是对于文件的操作,还有直接从终端输出,显示到显示器上。在C语言中,我们使用fopen,fclose,fread,fwrite对文件进…

[linux]wait详解

wait:进程等待 主要有两种等待方式:阻塞式等待和非阻塞式等待 阻塞式等待:如果子进程正在运行,父进程将会一直等待着子进程运行结束,并且自己什么事都不干 非阻塞式等待:如果子进程正在运行,…

[Linux]消息队列

我们知道进程间通信的方法有多种,主要有管道,消息队列,信号量,共享内存,socket等。之前介绍过管道,今天再介绍一个新的概念–消息队列。 消息队列:将一个进程到另一个进程之间发送数据块的方式…

C++关键字速查手册

[TOC] https://blog.csdn.net/csdn_kou/article/details/81113215 C98关键字 C11 关键字共73个 alignas alignof用于获取取指定表达式指定的(类似sizeof,可以直接是类型名)的对齐(alignment)。alignas用于声明时指定对齐类似于现有的类型…

[Linux]信号

Linux下的信号是一个什么概念呢。我们在现实生活中也遇到过信号之类的。比如红绿信号灯,班主任叫你去办公室并且脸色不好,诸如此类的都会给你一个信号。让你辨别事情的发生。同样,Linux下也有许多的信号,让你执行相应的操作。比如…

[数据结构]Map和Set

说起map和set,想必我们都学过红黑树了吧,map和set就是红黑树的一个应用领域。它的底层就是由红黑树来实现的。下面简单说一下map和set的使用吧。 首先,有一个栗子是这样的,让我们统计出每种水果出现的次数。 我们会想到怎么解决…

linux之信号

信号:在生活中,我们遇到过不同种类的信号,比如:(交通信号,乃至某个人的表情,动作等带给你不同的信号)然而,在我们的linux下,我们最熟悉的就是,当遇…

[Linux]继续探究mysleep函数(竞态条件)

之前我们探究过mysleep的简单用法&#xff0c;我们实现的代码是这样的&#xff1a; #include<stdio.h> #include<signal.h>void myhandler(int sig) {}unsigned int mysleep(unsigned int timeout) {struct sigaction act,oact;act.sa_handler myhandler;sigempt…

[Linux]死锁

死锁是指多个进程在运行过程中因争夺资源而造成的一种僵局&#xff0c;当进程处于这种僵持状态时&#xff0c;若无外力作用&#xff0c;它们都将无法再向前推进。之前信号量的时候我们知道&#xff0c;如果多个进程等待&#xff0c;主要体现在占有锁的问题上。死锁也可以被定义…