task_struct 結構如何查看及分析

    cd /find -name sched.hvim usr/src/kernels/3.10.0862.6.3.el7.x86_64/include/linux/sched.h

https://www.cnblogs.com/zxc2man/p/6649771.html

進程是處于執行期的程序以及它所管理的資源(如打開的文件、掛起的信號、進程狀態、地址空間等等)的總稱。注意,程序并不是進程,實際上兩個或多個進程不僅有可能執行同一程序,而且還有可能共享地址空間等資源。

Linux內核通過一個被稱為進程描述符的task_struct結構體來管理進程,這個結構體包含了一個進程所需的所有信息。它定義在linux-2.6.38.8/include/linux/sched.h文件中。本文將盡力就task_struct結構體所有成員的用法進行簡要說明。1、進程狀態 

[cpp] view plain copy print?
volatile long state;
int exit_state;
volatile long state;
int exit_state;
state成員的可能取值如下:

[cpp] view plain copy print?
#define TASK_RUNNING 0
#define TASK_INTERRUPTIBLE 1
#define TASK_UNINTERRUPTIBLE 2
#define __TASK_STOPPED 4
#define __TASK_TRACED 8
/* in tsk->exit_state /
#define EXIT_ZOMBIE 16
#define EXIT_DEAD 32
/
in tsk->state again /
#define TASK_DEAD 64
#define TASK_WAKEKILL 128
#define TASK_WAKING 256
#define TASK_RUNNING 0
#define TASK_INTERRUPTIBLE 1
#define TASK_UNINTERRUPTIBLE 2
#define __TASK_STOPPED 4
#define __TASK_TRACED 8
/
in tsk->exit_state /
#define EXIT_ZOMBIE 16
#define EXIT_DEAD 32
/
in tsk->state again */
#define TASK_DEAD 64
#define TASK_WAKEKILL 128
#define TASK_WAKING 256
系統中的每個進程都必然處于以上所列進程狀態中的一種。

TASK_RUNNING表示進程要么正在執行,要么正要準備執行。TASK_INTERRUPTIBLE表示進程被阻塞(睡眠),直到某個條件變為真。條件一旦達成,進程的狀態就被設置為TASK_RUNNING。TASK_UNINTERRUPTIBLE的意義與TASK_INTERRUPTIBLE類似,除了不能通過接受一個信號來喚醒以外。__TASK_STOPPED表示進程被停止執行。__TASK_TRACED表示進程被debugger等進程監視。EXIT_ZOMBIE表示進程的執行被終止,但是其父進程還沒有使用wait()等系統調用來獲知它的終止信息。EXIT_DEAD表示進程的最終狀態。EXIT_ZOMBIE和EXIT_DEAD也可以存放在exit_state成員中。進程狀態的切換過程和原因大致如下圖(圖片來自《Linux Kernel Development》):2、進程標識符(PID) 

[cpp] view plain copy print?
pid_t pid;
pid_t tgid;

pid_t pid;
pid_t tgid;
在CONFIG_BASE_SMALL配置為0的情況下,PID的取值范圍是0到32767,即系統中的進程數最大為32768個。 

[cpp] view plain copy print?
/* linux-2.6.38.8/include/linux/threads.h */
#define PID_MAX_DEFAULT (CONFIG_BASE_SMALL ? 0x1000 : 0x8000)

/* linux-2.6.38.8/include/linux/threads.h */
#define PID_MAX_DEFAULT (CONFIG_BASE_SMALL ? 0x1000 : 0x8000)
在Linux系統中,一個線程組中的所有線程使用和該線程組的領頭線程(該組中的第一個輕量級進程)相同的PID,并被存放在tgid成員中。只有線程組的領頭線程的pid成員才會被設置為與tgid相同的值。注意,getpid()系統調用返回的是當前進程的tgid值而不是pid值。

3、進程內核棧 

[cpp] view plain copy print?
void *stack;

void *stack;
進程通過alloc_thread_info函數分配它的內核棧,通過free_thread_info函數釋放所分配的內核棧。 

[cpp] view plain copy print?
/* linux-2.6.38.8/kernel/fork.c */
static inline struct thread_info *alloc_thread_info(struct task_struct *tsk)
{
#ifdef CONFIG_DEBUG_STACK_USAGE
gfp_t mask = GFP_KERNEL | __GFP_ZERO;
#else
gfp_t mask = GFP_KERNEL;
#endif
return (struct thread_info *)__get_free_pages(mask, THREAD_SIZE_ORDER);
}
static inline void free_thread_info(struct thread_info *ti)
{
free_pages((unsigned long)ti, THREAD_SIZE_ORDER);
}

/* linux-2.6.38.8/kernel/fork.c */
static inline struct thread_info *alloc_thread_info(struct task_struct *tsk)
{
#ifdef CONFIG_DEBUG_STACK_USAGE
gfp_t mask = GFP_KERNEL | __GFP_ZERO;
#else
gfp_t mask = GFP_KERNEL;
#endif
return (struct thread_info *)__get_free_pages(mask, THREAD_SIZE_ORDER);
}
static inline void free_thread_info(struct thread_info *ti)
{
free_pages((unsigned long)ti, THREAD_SIZE_ORDER);
}
其中,THREAD_SIZE_ORDER宏在linux-2.6.38.8/arch/arm/include/asm/thread_info.h文件中被定義為1,也就是說alloc_thread_info函數通過調用__get_free_pages函數分配2個頁的內存(它的首地址是8192字節對齊的)。

Linux內核通過thread_union聯合體來表示進程的內核棧,其中THREAD_SIZE宏的大小為8192。 

[cpp] view plain copy print?
union thread_union {
struct thread_info thread_info;
unsigned long stack[THREAD_SIZE/sizeof(long)];
};

union thread_union {
struct thread_info thread_info;
unsigned long stack[THREAD_SIZE/sizeof(long)];
};
當進程從用戶態切換到內核態時,進程的內核棧總是空的,所以ARM的sp寄存器指向這個棧的頂端。因此,內核能夠輕易地通過sp寄存器獲得當前正在CPU上運行的進程。

[cpp] view plain copy print?
/* linux-2.6.38.8/arch/arm/include/asm/current.h */
static inline struct task_struct *get_current(void)
{
return current_thread_info()->task;
}

#define current (get_current())

/* linux-2.6.38.8/arch/arm/include/asm/thread_info.h */
static inline struct thread_info *current_thread_info(void)
{
register unsigned long sp asm (“sp”);
return (struct thread_info )(sp & ~(THREAD_SIZE - 1));
}
/
linux-2.6.38.8/arch/arm/include/asm/current.h */
static inline struct task_struct *get_current(void)
{
return current_thread_info()->task;
}

#define current (get_current())

/* linux-2.6.38.8/arch/arm/include/asm/thread_info.h */
static inline struct thread_info *current_thread_info(void)
{
register unsigned long sp asm (“sp”);
return (struct thread_info *)(sp & ~(THREAD_SIZE - 1));
}
進程內核棧與進程描述符的關系如下圖:

4、標記 

[cpp] view plain copy print?
unsigned int flags; /* per process flags, defined below */

unsigned int flags;	/* per process flags, defined below */
flags成員的可能取值如下: 

[cpp] view plain copy print?
#define PF_KSOFTIRQD 0x00000001 /* I am ksoftirqd /
#define PF_STARTING 0x00000002 /
being created /
#define PF_EXITING 0x00000004 /
getting shut down /
#define PF_EXITPIDONE 0x00000008 /
pi exit done on shut down /
#define PF_VCPU 0x00000010 /
I’m a virtual CPU /
#define PF_WQ_WORKER 0x00000020 /
I’m a workqueue worker /
#define PF_FORKNOEXEC 0x00000040 /
forked but didn’t exec /
#define PF_MCE_PROCESS 0x00000080 /
process policy on mce errors /
#define PF_SUPERPRIV 0x00000100 /
used super-user privileges /
#define PF_DUMPCORE 0x00000200 /
dumped core /
#define PF_SIGNALED 0x00000400 /
killed by a signal /
#define PF_MEMALLOC 0x00000800 /
Allocating memory /
#define PF_USED_MATH 0x00002000 /
if unset the fpu must be initialized before use /
#define PF_FREEZING 0x00004000 /
freeze in progress. do not account to load /
#define PF_NOFREEZE 0x00008000 /
this thread should not be frozen /
#define PF_FROZEN 0x00010000 /
frozen for system suspend /
#define PF_FSTRANS 0x00020000 /
inside a filesystem transaction /
#define PF_KSWAPD 0x00040000 /
I am kswapd /
#define PF_OOM_ORIGIN 0x00080000 /
Allocating much memory to others /
#define PF_LESS_THROTTLE 0x00100000 /
Throttle me less: I clean memory /
#define PF_KTHREAD 0x00200000 /
I am a kernel thread /
#define PF_RANDOMIZE 0x00400000 /
randomize virtual address space /
#define PF_SWAPWRITE 0x00800000 /
Allowed to write to swap /
#define PF_SPREAD_PAGE 0x01000000 /
Spread page cache over cpuset /
#define PF_SPREAD_SLAB 0x02000000 /
Spread some slab caches over cpuset /
#define PF_THREAD_BOUND 0x04000000 /
Thread bound to specific cpu /
#define PF_MCE_EARLY 0x08000000 /
Early kill for mce process policy /
#define PF_MEMPOLICY 0x10000000 /
Non-default NUMA mempolicy /
#define PF_MUTEX_TESTER 0x20000000 /
Thread belongs to the rt mutex tester /
#define PF_FREEZER_SKIP 0x40000000 /
Freezer should not count it as freezable /
#define PF_FREEZER_NOSIG 0x80000000 /
Freezer won’t send signals to it /
#define PF_KSOFTIRQD 0x00000001 /
I am ksoftirqd /
#define PF_STARTING 0x00000002 /
being created /
#define PF_EXITING 0x00000004 /
getting shut down /
#define PF_EXITPIDONE 0x00000008 /
pi exit done on shut down /
#define PF_VCPU 0x00000010 /
I’m a virtual CPU /
#define PF_WQ_WORKER 0x00000020 /
I’m a workqueue worker /
#define PF_FORKNOEXEC 0x00000040 /
forked but didn’t exec /
#define PF_MCE_PROCESS 0x00000080 /
process policy on mce errors /
#define PF_SUPERPRIV 0x00000100 /
used super-user privileges /
#define PF_DUMPCORE 0x00000200 /
dumped core /
#define PF_SIGNALED 0x00000400 /
killed by a signal /
#define PF_MEMALLOC 0x00000800 /
Allocating memory /
#define PF_USED_MATH 0x00002000 /
if unset the fpu must be initialized before use /
#define PF_FREEZING 0x00004000 /
freeze in progress. do not account to load /
#define PF_NOFREEZE 0x00008000 /
this thread should not be frozen /
#define PF_FROZEN 0x00010000 /
frozen for system suspend /
#define PF_FSTRANS 0x00020000 /
inside a filesystem transaction /
#define PF_KSWAPD 0x00040000 /
I am kswapd /
#define PF_OOM_ORIGIN 0x00080000 /
Allocating much memory to others /
#define PF_LESS_THROTTLE 0x00100000 /
Throttle me less: I clean memory /
#define PF_KTHREAD 0x00200000 /
I am a kernel thread /
#define PF_RANDOMIZE 0x00400000 /
randomize virtual address space /
#define PF_SWAPWRITE 0x00800000 /
Allowed to write to swap /
#define PF_SPREAD_PAGE 0x01000000 /
Spread page cache over cpuset /
#define PF_SPREAD_SLAB 0x02000000 /
Spread some slab caches over cpuset /
#define PF_THREAD_BOUND 0x04000000 /
Thread bound to specific cpu /
#define PF_MCE_EARLY 0x08000000 /
Early kill for mce process policy /
#define PF_MEMPOLICY 0x10000000 /
Non-default NUMA mempolicy /
#define PF_MUTEX_TESTER 0x20000000 /
Thread belongs to the rt mutex tester /
#define PF_FREEZER_SKIP 0x40000000 /
Freezer should not count it as freezable /
#define PF_FREEZER_NOSIG 0x80000000 /
Freezer won’t send signals to it */
5、表示進程親屬關系的成員

[cpp] view plain copy print?
struct task_struct real_parent; / real parent process */
struct task_struct parent; / recipient of SIGCHLD, wait4() reports /
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 */
struct task_struct real_parent; / real parent process */
struct task_struct parent; / recipient of SIGCHLD, wait4() reports /
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 */
在Linux系統中,所有進程之間都有著直接或間接地聯系,每個進程都有其父進程,也可能有零個或多個子進程。擁有同一父進程的所有進程具有兄弟關系。

real_parent指向其父進程,如果創建它的父進程不再存在,則指向PID為1的init進程。parent指向其父進程,當它終止時,必須向它的父進程發送信號。它的值通常與real_parent相同。children表示鏈表的頭部,鏈表中的所有元素都是它的子進程。sibling用于把當前進程插入到兄弟鏈表中。group_leader指向其所在進程組的領頭進程。6、ptrace系統調用 

[cpp] view plain copy print?
unsigned int ptrace;
struct list_head ptraced;
struct list_head ptrace_entry;
unsigned long ptrace_message;
siginfo_t last_siginfo; / For ptrace use. */
ifdef CONFIG_HAVE_HW_BREAKPOINT
atomic_t ptrace_bp_refcnt;
endif

unsigned int ptrace;
struct list_head ptraced;
struct list_head ptrace_entry;
unsigned long ptrace_message;
siginfo_t *last_siginfo; /* For ptrace use.  */

#ifdef CONFIG_HAVE_HW_BREAKPOINT
atomic_t ptrace_bp_refcnt;
#endif
成員ptrace被設置為0時表示不需要被跟蹤,它的可能取值如下:

[cpp] view plain copy print?
/* linux-2.6.38.8/include/linux/ptrace.h /
#define PT_PTRACED 0x00000001
#define PT_DTRACE 0x00000002 /
delayed trace (used on m68k, i386) /
#define PT_TRACESYSGOOD 0x00000004
#define PT_PTRACE_CAP 0x00000008 /
ptracer can follow suid-exec */
#define PT_TRACE_FORK 0x00000010
#define PT_TRACE_VFORK 0x00000020
#define PT_TRACE_CLONE 0x00000040
#define PT_TRACE_EXEC 0x00000080
#define PT_TRACE_VFORK_DONE 0x00000100
#define PT_TRACE_EXIT 0x00000200

/* linux-2.6.38.8/include/linux/ptrace.h /
#define PT_PTRACED 0x00000001
#define PT_DTRACE 0x00000002 /
delayed trace (used on m68k, i386) /
#define PT_TRACESYSGOOD 0x00000004
#define PT_PTRACE_CAP 0x00000008 /
ptracer can follow suid-exec */
#define PT_TRACE_FORK 0x00000010
#define PT_TRACE_VFORK 0x00000020
#define PT_TRACE_CLONE 0x00000040
#define PT_TRACE_EXEC 0x00000080
#define PT_TRACE_VFORK_DONE 0x00000100
#define PT_TRACE_EXIT 0x00000200
7、Performance Event

[cpp] view plain copy print?
#ifdef CONFIG_PERF_EVENTS
struct perf_event_context *perf_event_ctxp[perf_nr_task_contexts];
struct mutex perf_event_mutex;
struct list_head perf_event_list;
#endif

#ifdef CONFIG_PERF_EVENTS
struct perf_event_context *perf_event_ctxp[perf_nr_task_contexts];
struct mutex perf_event_mutex;
struct list_head perf_event_list;
#endif
Performance Event是一款隨 Linux 內核代碼一同發布和維護的性能診斷工具。這些成員用于幫助PerformanceEvent分析進程的性能問題。

關于Performance Event工具的介紹可參考文章http://www.ibm.com/developerworks/cn/linux/l-cn-perf1/index.html?ca=drs-#major1和http://www.ibm.com/developerworks/cn/linux/l-cn-perf2/index.html?ca=drs-#major1。8、進程調度 

[cpp] view plain copy print?
int prio, static_prio, normal_prio;
unsigned int rt_priority;
const struct sched_class *sched_class;
struct sched_entity se;
struct sched_rt_entity rt;
unsigned int policy;
cpumask_t cpus_allowed;

int prio, static_prio, normal_prio;
unsigned int rt_priority;
const struct sched_class *sched_class;
struct sched_entity se;
struct sched_rt_entity rt;
unsigned int policy;
cpumask_t cpus_allowed;
實時優先級范圍是0到MAX_RT_PRIO-1(即99),而普通進程的靜態優先級范圍是從MAX_RT_PRIO到MAX_PRIO-1(即100到139)。值越大靜態優先級越低。 

[cpp] view plain copy print?
/* linux-2.6.38.8/include/linux/sched.h */
#define MAX_USER_RT_PRIO 100
#define MAX_RT_PRIO MAX_USER_RT_PRIO

#define MAX_PRIO (MAX_RT_PRIO + 40)
#define DEFAULT_PRIO (MAX_RT_PRIO + 20)

/* linux-2.6.38.8/include/linux/sched.h */
#define MAX_USER_RT_PRIO 100
#define MAX_RT_PRIO MAX_USER_RT_PRIO

#define MAX_PRIO (MAX_RT_PRIO + 40)
#define DEFAULT_PRIO (MAX_RT_PRIO + 20)
static_prio用于保存靜態優先級,可以通過nice系統調用來進行修改。

rt_priority用于保存實時優先級。normal_prio的值取決于靜態優先級和調度策略。prio用于保存動態優先級。policy表示進程的調度策略,目前主要有以下五種: 

[cpp] view plain copy print?
#define SCHED_NORMAL 0
#define SCHED_FIFO 1
#define SCHED_RR 2
#define SCHED_BATCH 3
/* SCHED_ISO: reserved but not implemented yet */
#define SCHED_IDLE 5

#define SCHED_NORMAL 0
#define SCHED_FIFO 1
#define SCHED_RR 2
#define SCHED_BATCH 3
/* SCHED_ISO: reserved but not implemented yet */
#define SCHED_IDLE 5
SCHED_NORMAL用于普通進程,通過CFS調度器實現。SCHED_BATCH用于非交互的處理器消耗型進程。SCHED_IDLE是在系統負載很低時使用。

SCHED_FIFO(先入先出調度算法)和SCHED_RR(輪流調度算法)都是實時調度策略。sched_class結構體表示調度類,目前內核中有實現以下四種: 

[cpp] view plain copy print?
/* linux-2.6.38.8/kernel/sched_fair.c /
static const struct sched_class fair_sched_class;
/
linux-2.6.38.8/kernel/sched_rt.c /
static const struct sched_class rt_sched_class;
/
linux-2.6.38.8/kernel/sched_idletask.c /
static const struct sched_class idle_sched_class;
/
linux-2.6.38.8/kernel/sched_stoptask.c */
static const struct sched_class stop_sched_class;

/* linux-2.6.38.8/kernel/sched_fair.c /
static const struct sched_class fair_sched_class;
/
linux-2.6.38.8/kernel/sched_rt.c /
static const struct sched_class rt_sched_class;
/
linux-2.6.38.8/kernel/sched_idletask.c /
static const struct sched_class idle_sched_class;
/
linux-2.6.38.8/kernel/sched_stoptask.c */
static const struct sched_class stop_sched_class;
se和rt都是調用實體,一個用于普通進程,一個用于實時進程,每個進程都有其中之一的實體。

cpus_allowed用于控制進程可以在哪里處理器上運行。

9、進程地址空間

[cpp] view plain copy print?
struct mm_struct *mm, *active_mm;
#ifdef CONFIG_COMPAT_BRK
unsigned brk_randomized:1;
#endif
#if defined(SPLIT_RSS_COUNTING)
struct task_rss_stat rss_stat;
#endif

struct mm_struct *mm, *active_mm;

#ifdef CONFIG_COMPAT_BRK
unsigned brk_randomized:1;
#endif
#if defined(SPLIT_RSS_COUNTING)
struct task_rss_stat rss_stat;
#endif
mm指向進程所擁有的內存描述符,而active_mm指向進程運行時所使用的內存描述符。對于普通進程而言,這兩個指針變量的值相同。但是,內核線程不擁有任何內存描述符,所以它們的mm成員總是為NULL。當內核線程得以運行時,它的active_mm成員被初始化為前一個運行進程的active_mm值。

brk_randomized的用法在http://lkml.indiana.edu/hypermail/Linux/kernel/1104.1/00196.html上有介紹,用來確定對隨機堆內存的探測。rss_stat用來記錄緩沖信息。 10、判斷標志 

[cpp] view plain copy print?
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;
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;
exit_code用于設置進程的終止代號,這個值要么是_exit()或exit_group()系統調用參數(正常終止),要么是由內核提供的一個錯誤代號(異常終止)。exit_signal被置為-1時表示是某個線程組中的一員。只有當線程組的最后一個成員終止時,才會產生一個信號,以通知線程組的領頭進程的父進程。pdeath_signal用于判斷父進程終止時發送信號。personality用于處理不同的ABI,它的可能取值如下: 

[cpp] view plain copy print?
enum {
PER_LINUX = 0x0000,
PER_LINUX_32BIT = 0x0000 | ADDR_LIMIT_32BIT,
PER_LINUX_FDPIC = 0x0000 | FDPIC_FUNCPTRS,
PER_SVR4 = 0x0001 | STICKY_TIMEOUTS | MMAP_PAGE_ZERO,
PER_SVR3 = 0x0002 | STICKY_TIMEOUTS | SHORT_INODE,
PER_SCOSVR3 = 0x0003 | STICKY_TIMEOUTS |
WHOLE_SECONDS | SHORT_INODE,
PER_OSR5 = 0x0003 | STICKY_TIMEOUTS | WHOLE_SECONDS,
PER_WYSEV386 = 0x0004 | STICKY_TIMEOUTS | SHORT_INODE,
PER_ISCR4 = 0x0005 | STICKY_TIMEOUTS,
PER_BSD = 0x0006,
PER_SUNOS = 0x0006 | STICKY_TIMEOUTS,
PER_XENIX = 0x0007 | STICKY_TIMEOUTS | SHORT_INODE,
PER_LINUX32 = 0x0008,
PER_LINUX32_3GB = 0x0008 | ADDR_LIMIT_3GB,
PER_IRIX32 = 0x0009 | STICKY_TIMEOUTS,/* IRIX5 32-bit /
PER_IRIXN32 = 0x000a | STICKY_TIMEOUTS,/
IRIX6 new 32-bit /
PER_IRIX64 = 0x000b | STICKY_TIMEOUTS,/
IRIX6 64-bit /
PER_RISCOS = 0x000c,
PER_SOLARIS = 0x000d | STICKY_TIMEOUTS,
PER_UW7 = 0x000e | STICKY_TIMEOUTS | MMAP_PAGE_ZERO,
PER_OSF4 = 0x000f, /
OSF/1 v4 /
PER_HPUX = 0x0010,
PER_MASK = 0x00ff,
};
enum {
PER_LINUX = 0x0000,
PER_LINUX_32BIT = 0x0000 | ADDR_LIMIT_32BIT,
PER_LINUX_FDPIC = 0x0000 | FDPIC_FUNCPTRS,
PER_SVR4 = 0x0001 | STICKY_TIMEOUTS | MMAP_PAGE_ZERO,
PER_SVR3 = 0x0002 | STICKY_TIMEOUTS | SHORT_INODE,
PER_SCOSVR3 = 0x0003 | STICKY_TIMEOUTS |
WHOLE_SECONDS | SHORT_INODE,
PER_OSR5 = 0x0003 | STICKY_TIMEOUTS | WHOLE_SECONDS,
PER_WYSEV386 = 0x0004 | STICKY_TIMEOUTS | SHORT_INODE,
PER_ISCR4 = 0x0005 | STICKY_TIMEOUTS,
PER_BSD = 0x0006,
PER_SUNOS = 0x0006 | STICKY_TIMEOUTS,
PER_XENIX = 0x0007 | STICKY_TIMEOUTS | SHORT_INODE,
PER_LINUX32 = 0x0008,
PER_LINUX32_3GB = 0x0008 | ADDR_LIMIT_3GB,
PER_IRIX32 = 0x0009 | STICKY_TIMEOUTS,/
IRIX5 32-bit /
PER_IRIXN32 = 0x000a | STICKY_TIMEOUTS,/
IRIX6 new 32-bit /
PER_IRIX64 = 0x000b | STICKY_TIMEOUTS,/
IRIX6 64-bit /
PER_RISCOS = 0x000c,
PER_SOLARIS = 0x000d | STICKY_TIMEOUTS,
PER_UW7 = 0x000e | STICKY_TIMEOUTS | MMAP_PAGE_ZERO,
PER_OSF4 = 0x000f, /
OSF/1 v4 */
PER_HPUX = 0x0010,
PER_MASK = 0x00ff,
};
did_exec用于記錄進程代碼是否被execve()函數所執行。

in_execve用于通知LSM是否被do_execve()函數所調用。詳見補丁說明:http://lkml.indiana.edu/hypermail/linux/kernel/0901.1/00014.html。in_iowait用于判斷是否進行iowait計數。sched_reset_on_fork用于判斷是否恢復默認的優先級或調度策略。11、時間 

[cpp] view plain copy print?
cputime_t utime, stime, utimescaled, stimescaled;
cputime_t gtime;
#ifndef CONFIG_VIRT_CPU_ACCOUNTING
cputime_t prev_utime, prev_stime;
#endif
unsigned long nvcsw, nivcsw; /* context switch counts /
struct timespec start_time; /
monotonic time /
struct timespec real_start_time; /
boot based time /
struct task_cputime cputime_expires;
struct list_head cpu_timers[3];
#ifdef CONFIG_DETECT_HUNG_TASK
/
hung task detection /
unsigned long last_switch_count;
#endif
cputime_t utime, stime, utimescaled, stimescaled;
cputime_t gtime;
#ifndef CONFIG_VIRT_CPU_ACCOUNTING
cputime_t prev_utime, prev_stime;
#endif
unsigned long nvcsw, nivcsw; /
context switch counts /
struct timespec start_time; /
monotonic time /
struct timespec real_start_time; /
boot based time /
struct task_cputime cputime_expires;
struct list_head cpu_timers[3];
#ifdef CONFIG_DETECT_HUNG_TASK
/
hung task detection */
unsigned long last_switch_count;
#endif
utime/stime用于記錄進程在用戶態/內核態下所經過的節拍數(定時器)。prev_utime/prev_stime是先前的運行時間,請參考補丁說明http://lkml.indiana.edu/hypermail/linux/kernel/1003.3/02431.html。

utimescaled/stimescaled也是用于記錄進程在用戶態/內核態的運行時間,但它們以處理器的頻率為刻度。gtime是以節拍計數的虛擬機運行時間(guest time)。nvcsw/nivcsw是自愿(voluntary)/非自愿(involuntary)上下文切換計數。last_switch_count是nvcsw和nivcsw的總和。start_time和real_start_time都是進程創建時間,real_start_time還包含了進程睡眠時間,常用于/proc/pid/stat,補丁說明請參考http://lkml.indiana.edu/hypermail/linux/kernel/0705.0/2094.html。cputime_expires用來統計進程或進程組被跟蹤的處理器時間,其中的三個成員對應著cpu_timers[3]的三個鏈表。12、信號處理 

[cpp] view plain copy print?
/* 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;  

/* 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;
signal指向進程的信號描述符。sighand指向進程的信號處理程序描述符。blocked表示被阻塞信號的掩碼,real_blocked表示臨時掩碼。pending存放私有掛起信號的數據結構。sas_ss_sp是信號處理程序備用堆棧的地址,sas_ss_size表示堆棧的大小。設備驅動程序常用notifier指向的函數來阻塞進程的某些信號(notifier_mask是這些信號的位掩碼),notifier_data指的是notifier所指向的函數可能使用的數據。13、其他(1)、用于保護資源分配或釋放的自旋鎖 

[cpp] view plain copy print?
/* Protection of (de-)allocation: mm, files, fs, tty, keyrings, mems_allowed,

  • mempolicy */
    spinlock_t alloc_lock;

/* Protection of (de-)allocation: mm, files, fs, tty, keyrings, mems_allowed,

  • mempolicy */
    spinlock_t alloc_lock;
    (2)、進程描述符使用計數,被置為2時,表示進程描述符正在被使用而且其相應的進程處于活動狀態。

[cpp] view plain copy print?
atomic_t usage;

atomic_t usage;
(3)、用于表示獲取大內核鎖的次數,如果進程未獲得過鎖,則置為-1。 

[cpp] view plain copy print?
int lock_depth; /* BKL lock depth */

int lock_depth;		/* BKL lock depth */
(4)、在SMP上幫助實現無加鎖的進程切換(unlocked context switches) 

[cpp] view plain copy print?
#ifdef CONFIG_SMP
#ifdef __ARCH_WANT_UNLOCKED_CTXSW
int oncpu;
#endif
#endif
#ifdef CONFIG_SMP
#ifdef __ARCH_WANT_UNLOCKED_CTXSW
int oncpu;
#endif
#endif
(5)、preempt_notifier結構體鏈表

[cpp] view plain copy print?
#ifdef CONFIG_PREEMPT_NOTIFIERS
/* list of struct preempt_notifier: */
struct hlist_head preempt_notifiers;
#endif

#ifdef CONFIG_PREEMPT_NOTIFIERS
/* list of struct preempt_notifier: */
struct hlist_head preempt_notifiers;
#endif
(6)、FPU使用計數

[cpp] view plain copy print?
unsigned char fpu_counter;

unsigned char fpu_counter;
(7)、blktrace是一個針對Linux內核中塊設備I/O層的跟蹤工具。 

[cpp] view plain copy print?
#ifdef CONFIG_BLK_DEV_IO_TRACE
unsigned int btrace_seq;
#endif
#ifdef CONFIG_BLK_DEV_IO_TRACE
unsigned int btrace_seq;
#endif
(8)、RCU同步原語

[cpp] view plain copy print?
#ifdef CONFIG_PREEMPT_RCU
int rcu_read_lock_nesting;
char rcu_read_unlock_special;
struct list_head rcu_node_entry;
#endif /* #ifdef CONFIG_PREEMPT_RCU */
#ifdef CONFIG_TREE_PREEMPT_RCU
struct rcu_node rcu_blocked_node;
#endif /
#ifdef CONFIG_TREE_PREEMPT_RCU */
#ifdef CONFIG_RCU_BOOST
struct rt_mutex rcu_boost_mutex;
#endif /
#ifdef CONFIG_RCU_BOOST */

#ifdef CONFIG_PREEMPT_RCU
int rcu_read_lock_nesting;
char rcu_read_unlock_special;
struct list_head rcu_node_entry;
#endif /* #ifdef CONFIG_PREEMPT_RCU */
#ifdef CONFIG_TREE_PREEMPT_RCU
struct rcu_node rcu_blocked_node;
#endif /
#ifdef CONFIG_TREE_PREEMPT_RCU */
#ifdef CONFIG_RCU_BOOST
struct rt_mutex rcu_boost_mutex;
#endif /
#ifdef CONFIG_RCU_BOOST */
(9)、用于調度器統計進程的運行信息

[cpp] view plain copy print?
#if defined(CONFIG_SCHEDSTATS) || defined(CONFIG_TASK_DELAY_ACCT)
struct sched_info sched_info;
#endif
#if defined(CONFIG_SCHEDSTATS) || defined(CONFIG_TASK_DELAY_ACCT)
struct sched_info sched_info;
#endif
(10)、用于構建進程鏈表

[cpp] view plain copy print?
struct list_head tasks;

struct list_head tasks;
(11)、to limit pushing to one attempt 

[cpp] view plain copy print?
#ifdef CONFIG_SMP
struct plist_node pushable_tasks;
#endif

#ifdef CONFIG_SMP
struct plist_node pushable_tasks;
#endif
補丁說明請參考:http://lkml.indiana.edu/hypermail/linux/kernel/0808.3/0503.html

(12)、防止內核堆棧溢出 

[cpp] view plain copy print?
#ifdef CONFIG_CC_STACKPROTECTOR
/* Canary value for the -fstack-protector gcc feature /
unsigned long stack_canary;
#endif
#ifdef CONFIG_CC_STACKPROTECTOR
/
Canary value for the -fstack-protector gcc feature */
unsigned long stack_canary;
#endif
在GCC編譯內核時,需要加上-fstack-protector選項。

(13)、PID散列表和鏈表 

[cpp] view plain copy print?
/* PID/PID hash table linkage. */
struct pid_link pids[PIDTYPE_MAX];
struct list_head thread_group; //線程組中所有進程的鏈表

/* PID/PID hash table linkage. */
struct pid_link pids[PIDTYPE_MAX];
struct list_head thread_group; //線程組中所有進程的鏈表
(14)、do_fork函數 

[cpp] view plain copy print?
struct completion vfork_done; / for vfork() */
int __user set_child_tid; / CLONE_CHILD_SETTID */
int __user clear_child_tid; / CLONE_CHILD_CLEARTID */

struct completion *vfork_done;		/* for vfork() */
int __user *set_child_tid;		/* CLONE_CHILD_SETTID */
int __user *clear_child_tid;		/* CLONE_CHILD_CLEARTID */
在執行do_fork()時,如果給定特別標志,則vfork_done會指向一個特殊地址。如果copy_process函數的clone_flags參數的值被置為CLONE_CHILD_SETTID或CLONE_CHILD_CLEARTID,則會把child_tidptr參數的值分別復制到set_child_tid和clear_child_tid成員。這些標志說明必須改變子進程用戶態地址空間的child_tidptr所指向的變量的值。(15)、缺頁統計 

[cpp] view plain copy print?
/* mm fault and swap info: this can arguably be seen as either mm-specific or thread-specific */
unsigned long min_flt, maj_flt;

/* mm fault and swap info: this can arguably be seen as either mm-specific or thread-specific */
unsigned long min_flt, maj_flt;
(16)、進程權能

[cpp] view plain copy print?
const struct cred __rcu real_cred; / objective and real subjective task
* credentials (COW) */
const struct cred __rcu cred; / effective (overridable) subjective task
* credentials (COW) */
struct cred replacement_session_keyring; / for KEYCTL_SESSION_TO_PARENT */

const struct cred __rcu *real_cred; /* objective and real subjective task* credentials (COW) */
const struct cred __rcu *cred;	/* effective (overridable) subjective task* credentials (COW) */
struct cred *replacement_session_keyring; /* for KEYCTL_SESSION_TO_PARENT */
(17)、相應的程序名 

[cpp] view plain copy print?
char comm[TASK_COMM_LEN];
char comm[TASK_COMM_LEN];
(18)、文件

[cpp] view plain copy print?
/* file system info /
int link_count, total_link_count;
/
filesystem information */
struct fs_struct fs;
/
open file information */
struct files_struct *files;

/* file system info /
int link_count, total_link_count;
/
filesystem information */
struct fs_struct fs;
/
open file information */
struct files_struct *files;
fs用來表示進程與文件系統的聯系,包括當前目錄和根目錄。

files表示進程當前打開的文件。(19)、進程通信(SYSVIPC) 

[cpp] view plain copy print?
#ifdef CONFIG_SYSVIPC
/* ipc stuff /
struct sysv_sem sysvsem;
#endif
#ifdef CONFIG_SYSVIPC
/
ipc stuff */
struct sysv_sem sysvsem;
#endif
(20)、處理器特有數據

[cpp] view plain copy print?
/* CPU-specific state of this task */
struct thread_struct thread;

/* CPU-specific state of this task */
struct thread_struct thread;
(21)、命名空間

[cpp] view plain copy print?
/* namespaces */
struct nsproxy *nsproxy;

/* namespaces */
struct nsproxy *nsproxy;
(22)、進程審計

[cpp] view plain copy print?
struct audit_context *audit_context;
#ifdef CONFIG_AUDITSYSCALL
uid_t loginuid;
unsigned int sessionid;
#endif

struct audit_context *audit_context;

#ifdef CONFIG_AUDITSYSCALL
uid_t loginuid;
unsigned int sessionid;
#endif
(23)、secure computing

[cpp] view plain copy print?
seccomp_t seccomp;

seccomp_t seccomp;
(24)、用于copy_process函數使用CLONE_PARENT 標記時 

[cpp] view plain copy print?
/* Thread group tracking */
u32 parent_exec_id;
u32 self_exec_id;

/* Thread group tracking */
u32 parent_exec_id;
u32 self_exec_id;
(25)、中斷

[cpp] view plain copy print?
#ifdef CONFIG_GENERIC_HARDIRQS
/* IRQ handler threads */
struct irqaction irqaction;
#endif
#ifdef CONFIG_TRACE_IRQFLAGS
unsigned int irq_events;
unsigned long hardirq_enable_ip;
unsigned long hardirq_disable_ip;
unsigned int hardirq_enable_event;
unsigned int hardirq_disable_event;
int hardirqs_enabled;
int hardirq_context;
unsigned long softirq_disable_ip;
unsigned long softirq_enable_ip;
unsigned int softirq_disable_event;
unsigned int softirq_enable_event;
int softirqs_enabled;
int softirq_context;
#endif
#ifdef CONFIG_GENERIC_HARDIRQS
/
IRQ handler threads */
struct irqaction *irqaction;
#endif
#ifdef CONFIG_TRACE_IRQFLAGS
unsigned int irq_events;
unsigned long hardirq_enable_ip;
unsigned long hardirq_disable_ip;
unsigned int hardirq_enable_event;
unsigned int hardirq_disable_event;
int hardirqs_enabled;
int hardirq_context;
unsigned long softirq_disable_ip;
unsigned long softirq_enable_ip;
unsigned int softirq_disable_event;
unsigned int softirq_enable_event;
int softirqs_enabled;
int softirq_context;
#endif
(26)、task_rq_lock函數所使用的鎖

[cpp] view plain copy print?
/* Protection of the PI data structures: */
raw_spinlock_t pi_lock;

/* Protection of the PI data structures: */
raw_spinlock_t pi_lock;
(27)、基于PI協議的等待互斥鎖,其中PI指的是priority inheritance(優先級繼承) 

[cpp] view plain copy print?
#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_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
(28)、死鎖檢測

[cpp] view plain copy print?
#ifdef CONFIG_DEBUG_MUTEXES
/* mutex deadlock detection */
struct mutex_waiter blocked_on;
#endif
#ifdef CONFIG_DEBUG_MUTEXES
/
mutex deadlock detection */
struct mutex_waiter *blocked_on;
#endif
(29)、lockdep,參見內核說明文檔linux-2.6.38.8/Documentation/lockdep-design.txt

[cpp] view plain copy print?
#ifdef CONFIG_LOCKDEP

define MAX_LOCK_DEPTH 48UL

u64 curr_chain_key;  
int lockdep_depth;  
unsigned int lockdep_recursion;  
struct held_lock held_locks[MAX_LOCK_DEPTH];  
gfp_t lockdep_reclaim_gfp;  

#endif

#ifdef CONFIG_LOCKDEP

define MAX_LOCK_DEPTH 48UL

u64 curr_chain_key;
int lockdep_depth;
unsigned int lockdep_recursion;
struct held_lock held_locks[MAX_LOCK_DEPTH];
gfp_t lockdep_reclaim_gfp;

#endif
(30)、JFS文件系統

[cpp] view plain copy print?
/* journalling filesystem info */
void journal_info;
/
journalling filesystem info */
void *journal_info;
(31)、塊設備鏈表

[cpp] view plain copy print?
/* stacked block device info */
struct bio_list *bio_list;

/* stacked block device info */
struct bio_list *bio_list;
(32)、內存回收

[cpp] view plain copy print?
struct reclaim_state *reclaim_state;

struct reclaim_state *reclaim_state;
(33)、存放塊設備I/O數據流量信息

[cpp] view plain copy print?
struct backing_dev_info *backing_dev_info;

struct backing_dev_info *backing_dev_info;
(34)、I/O調度器所使用的信息 

[cpp] view plain copy print?
struct io_context *io_context;
struct io_context *io_context;
(35)、記錄進程的I/O計數

[cpp] view plain copy print?
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

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
在Ubuntu 11.04上,執行cat獲得進程1的I/O計數如下:

[cpp] view plain copy print?
$ sudo cat /proc/1/io

$ sudo cat /proc/1/io
[cpp] view plain copy print?
rchar: 164258906
wchar: 455212837
syscr: 388847
syscw: 92563
read_bytes: 439251968
write_bytes: 14143488
cancelled_write_bytes: 2134016
rchar: 164258906
wchar: 455212837
syscr: 388847
syscw: 92563
read_bytes: 439251968
write_bytes: 14143488
cancelled_write_bytes: 2134016
輸出的數據項剛好是task_io_accounting結構體的所有成員。

(36)、CPUSET功能 

[cpp] view plain copy print?
#ifdef CONFIG_CPUSETS
nodemask_t mems_allowed; /* Protected by alloc_lock */
int mems_allowed_change_disable;
int cpuset_mem_spread_rotor;
int cpuset_slab_spread_rotor;
#endif

#ifdef CONFIG_CPUSETS
nodemask_t mems_allowed; /* Protected by alloc_lock */
int mems_allowed_change_disable;
int cpuset_mem_spread_rotor;
int cpuset_slab_spread_rotor;
#endif
(37)、Control Groups

[cpp] view plain copy print?
#ifdef CONFIG_CGROUPS
/* Control Group info protected by css_set_lock */
struct css_set __rcu cgroups;
/
cg_list protected by css_set_lock and tsk->alloc_lock /
struct list_head cg_list;
#endif
#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
#ifdef CONFIG_CGROUPS
/
Control Group info protected by css_set_lock */
struct css_set __rcu cgroups;
/
cg_list protected by css_set_lock and tsk->alloc_lock /
struct list_head cg_list;
#endif
#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
(38)、futex同步機制

[cpp] view plain copy print?
#ifdef CONFIG_FUTEX
struct robust_list_head __user *robust_list;
#ifdef CONFIG_COMPAT
struct compat_robust_list_head __user *compat_robust_list;
#endif
struct list_head pi_state_list;
struct futex_pi_state *pi_state_cache;
#endif
#ifdef CONFIG_FUTEX
struct robust_list_head __user *robust_list;
#ifdef CONFIG_COMPAT
struct compat_robust_list_head __user *compat_robust_list;
#endif
struct list_head pi_state_list;
struct futex_pi_state *pi_state_cache;
#endif
(39)、非一致內存訪問(NUMA Non-Uniform Memory Access)

[cpp] view plain copy print?
#ifdef CONFIG_NUMA
struct mempolicy mempolicy; / Protected by alloc_lock */
short il_next;
#endif

#ifdef CONFIG_NUMA
struct mempolicy mempolicy; / Protected by alloc_lock */
short il_next;
#endif
(40)、文件系統互斥資源

[cpp] view plain copy print?
atomic_t fs_excl; /* holding fs exclusive resources */

atomic_t fs_excl;	/* holding fs exclusive resources */
(41)、RCU鏈表 

[cpp] view plain copy print?
struct rcu_head rcu;

struct rcu_head rcu;
(42)、管道 

[cpp] view plain copy print?
struct pipe_inode_info *splice_pipe;

struct pipe_inode_info *splice_pipe;
(43)、延遲計數 

[cpp] view plain copy print?
#ifdef CONFIG_TASK_DELAY_ACCT
struct task_delay_info *delays;
#endif

#ifdef CONFIG_TASK_DELAY_ACCT
struct task_delay_info *delays;
#endif
(44)、fault injection,參考內核說明文件linux-2.6.38.8/Documentation/fault-injection/fault-injection.txt

[cpp] view plain copy print?
#ifdef CONFIG_FAULT_INJECTION
int make_it_fail;
#endif
#ifdef CONFIG_FAULT_INJECTION
int make_it_fail;
#endif
(45)、FLoating proportions

[cpp] view plain copy print?
struct prop_local_single dirties;

struct prop_local_single dirties;
(46)、Infrastructure for displayinglatency 

[cpp] view plain copy print?
#ifdef CONFIG_LATENCYTOP
int latency_record_count;
struct latency_record latency_record[LT_SAVECOUNT];
#endif

#ifdef CONFIG_LATENCYTOP
int latency_record_count;
struct latency_record latency_record[LT_SAVECOUNT];
#endif
(47)、time slack values,常用于poll和select函數

[cpp] view plain copy print?
unsigned long timer_slack_ns;
unsigned long default_timer_slack_ns;
unsigned long timer_slack_ns;
unsigned long default_timer_slack_ns;
(48)、socket控制消息(control message)

[cpp] view plain copy print?
struct list_head *scm_work_list;

struct list_head	*scm_work_list;
(49)、ftrace跟蹤器 

[cpp] view plain copy print?
#ifdef CONFIG_FUNCTION_GRAPH_TRACER
/* Index of current stored address 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 */

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/382511.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/382511.shtml
英文地址,請注明出處:http://en.pswp.cn/news/382511.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

linux 與信號集操作相關的函數

與信號集操作相關的函數 #include <signal.h> 清空信號集 全都為0 int sigemptyset(sigset_t *set);填充信號集 全都為1 int sigfillset(sigset_t *set);添加某個信號到信號集 int sigaddset(sigset_t *set, int signum);從集合中刪除某個信號 int sigdelset(sigset_t *s…

軟件工程學習筆記《三》代碼優化和性能測試

文章目錄軟件工程學習筆記目錄如何在開源社區提問&#xff1f;代碼審查代碼優化運行結果參數解釋代碼優化原則對常見的數據結構排序算法進行測試關于冒泡排序優化的探討結果軟件工程學習筆記目錄 [https://blog.csdn.net/csdn_kou/article/details/83754356] 如何在開源社區提…

linux信號捕捉

信號捕捉&#xff0c;防止進程意外死亡 signal函數 man signal #include <signal.h> typedef void (*sighandler_t)(int); sighandler_t signal(int signum, sighandler_t handler);參數介紹&#xff1b; signum 要捕捉的信號 handler 要執行的捕捉函數指針&#xff0c…

軟件工程學習筆記《目錄》

軟件工程學習筆記《目錄》 軟件工程學習筆記《一》什么是軟件工程 軟件工程學習筆記《二》代碼規范 軟件工程學習筆記《三》代碼優化和性能測試 軟件工程學習筆記《四》需求分析

linux進程利用SIGCHLD信號,來實現父進程回收子進程

子進程執行完畢后&#xff0c;會向父進程發出 SIGCHLD信號 &#xff0c; 這段代碼實現的就是i&#xff0c;父進程接受到子進程 發出的SIGCHLD信號&#xff0c;實現對子進程進行回收&#xff0c;從而避免僵尸進程 #include <stdio.h> #include <unistd.h> #include…

WWW軟件全球使用排名

https://w3techs.com/technologies/overview/web_server/all Apache份額一直下降呀&#xff01;

軟件工程學習筆記《四》需求分析

文章目錄軟件工程學習筆記《目錄》需求工程師當代的需求工程師需要具備的能力當代的需求工程師需要努力的方向當代的需求工程師需要注意的錯誤需求的定義需求目標需求分析的實質需求分析的關鍵應該涵蓋的內容&#xff1f;需求規約&#xff08;作為較客觀的參照&#xff09;單個…

linux守護進程

先了解 linux系統中 會話的概念 會話是進程組的更高一級&#xff0c;多個進程組對應一個會話。 會話是一個或多個進程組的集合 創建一個會話需要注意以下5點事項&#xff1a; a. 調用進程不能是進程組組長&#xff0c; 該進程變成新會話首進程&#xff08;session header&#…

python3爬蟲學習筆記

文章目錄python3的文本處理jieba庫的使用統計hamlet.txt文本中高頻詞的個數統計三國演義任務高頻次數爬蟲爬取百度首頁爬取京東某手機頁面BeautifulSoup使用request進行爬取&#xff0c;在使用 BeautifulSoup進行處理&#xff01;擁有一個更好的排版BeautifulSoup爬取百度首頁原…

linux 線程學習初步01

線程的概念 進程與線程內核實現 通過函數clone實現的 ps -Lf pidLinux內核線程實現原理 同一個進程下的線程&#xff0c;共享該進程的內存區&#xff0c; 但是只有stack區域不共享。 線程共享資源 a.文件描述符表 b.每種信號的處理方式 c.當前工作目錄 d.用戶id和組id 線程…

python3字符串處理,高效切片

高級技巧&#xff1a;切片&#xff0c;迭代&#xff0c;列表&#xff0c;生成器 切片 L [Hello, World, !]print("-------1.一個一個取-------") print(L[0]) print(L[1]) print(L[2])print("-------2.開辟一個新列表把內容存進去-------") r [] for i…

linux線程學習初步02

殺死線程的函數 int pthread_cancel(pthread_t thread); 參數介紹&#xff1a;需要輸入的tid 返回值&#xff1a;識別返回 errno成功返回 0 被殺死的線程&#xff0c;退出狀態值為一個 #define PTHREAD_CANCELED((void *)-1)代碼案例&#xff1a; #include <stdio.h> #…

python的文件基本操作和文件指針

讀寫模式的基本操作 https://www.cnblogs.com/c-x-m/articles/7756498.html r,w,a r只讀模式【默認模式&#xff0c;文件必須存在&#xff0c;不存在則拋出異常】w只寫模式【不可讀&#xff1b;不存在則創建&#xff1b;存在則清空內容】a之追加寫模式【不可讀&#xff1b;不…

python3 將unicode轉中文

decrypted_str.encode(utf-8).decode(unicode_escape)

HTTP菜鳥教程速查手冊

HTTP協議&#xff08;HyperText Transfer Protocol&#xff0c;超文本傳輸協議&#xff09;是因特網上應用最為廣泛的一種網絡傳輸協議&#xff0c;所有的WWW文件都必須遵守這個標準。 HTTP是一個基于TCP/IP通信協議來傳遞數據&#xff08;HTML 文件, 圖片文件, 查詢結果等&am…

mysql學習筆記01-創建數據庫

創建數據庫&#xff1a; 校驗規則&#xff1a;是指表的排序規則和查詢時候的規則 utf8_general_ci 支持中文&#xff0c; 且不區分大小寫 utf8_bin 支持中文&#xff0c; 區分大小寫 比如&#xff1a; create database db3 character set utf8 collate utf8_general_ci; &…

python的Web編程

首先看一下效果 完整代碼 import socket from multiprocessing import ProcessHTML_ROOT_DIR ""def handle_client(client_socket):request_data client_socket.recv(1024)print("request data:", request_data)response_start_line "HTTP/1.0 20…

mysql 學習筆記 02創建表

表結構的創建 比如&#xff1a; create table userinfo (id int unsigned comment id號name varchar(60) comment 用戶名password char(32),birthday date ) character set utf8 engine MyISAM;comment 表示注釋的意思 不同的存儲引擎&#xff0c;創建的表的文件不一樣

mysql 學習筆記03 常用數據類型

數值類型&#xff1a; a. 整數類型&#xff1a; 注意事項&#xff1a; 舉例&#xff1a;某個整型字段 &#xff0c;不為空&#xff0c;且有默認值 create table test (age int unisigned not null default 1);zerofill的使用 b. bit類型的使用 c.小數類型 小數類型占用…