두근두근이야기

struct task_struct의 구조 - 수정필요 본문

IT/IT ::Advanced SystemProgramming

struct task_struct의 구조 - 수정필요

골든 2013. 3. 9. 00:38

아래 내용은 다음 블로그를 참고하였습니다 (http://rusy.tistory.com/17)

task_struct의 구조

struct task_struct{

(1)long state;

(2)mm_segment_t addr_limit;

(3)long need_resched;

(4)struct task_struct *next_task, *prev_task;

(5)struct task_struct *next_run, *prev_run;


(6)pid_t pid;

(7)struct task_struct *p_cptr, *p_pptr;

(8)uid_t uid, euid;


(9)struct rlimit rlim[RLIM_NLIMITS];

(10)struct tty_struct *tty;

(11)struct thread_struct thread;

(12)struct fs_struct *fs;

(13)struct files_struct *files;

(14)struct m_struct *mm;

}


일단 필요한 부분에 대한 변수만 기술하겠다.

(3)long need_resched;

이 프로세스로 인한 인터럽트 처리가 끝났을 때, need_reached = 1 이면 스케쥴러가 작동되어 다음 프로세스를 시작.





mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm

struct task_struct
{

/* offsets of these are hardcoded elsewhere - touch with care */
volatile long state; /* 프로세스 상태 :-1 unrunnable, 0 runnable, >0 stopped */

/* PF_ALIGNWARN : Alignment 경고 메시지를 출력하라. PF_STARTING : 현재 프로세스가 생성중이다.
PF_EXITING : 현재 프로세스가 멈추고 있다. PF_FORKNOEXEC : fork되었지만, exec를 호출하지 않았다.
PF_AUPPERPRIV : super user 권한으로 사용되고 있다. PF_DUMPCORE : core dump 되었다.
PF_SIGNALED : signal에 의해서 kill되었다. PF_MEMALLOC : 메모리를 할당하고 있다.
PF_VFORK : mm_release 시에 부모 프로세스를 깨워라.
PF_USEDFPU : Floating point unit을 프로세스가 현재 quantum 동안에 사용했다. */

unsigned long flags; /* 현재 시스템 상태 : per process flags, defined below */
int sigpending; /* 프로세스에 대해 전달되기 원하는 시그널 */

/* thread address space: 0 ~ 0xBFFFFFFF for user-thead 0 ~ 0xFFFFFFFF for kernel-thread */
mm_segment_t addr_limit; /* 커널과 사용자 프로세스 간에 사용할 수 있는 주소 영역 */
struct exec_domain *exec_domain;

/* 현재 프로세스가 커널 모드에서 실행 중일 때 커널에게 스케쥴링을 요구할 경우 need_resched 필드를 설정한다. */
volatile long need_resched;

/* PT_PTRACED : 현재 프로세스가 trace되고 있다. PT_DTRACE : 지연된 trace를 하고 있다.
PT_TRACESYS : 현재 프로세스가 trace되고 있으면, 다음 번 시스템 콜까지 진핸하다.
PT_TRACESYSGOOD : 현재 프로세스가 trace되고 있으며, 시스템 콜이 에러가 없을 때까지 진행한다. */
unsigned long ptrace; /* 디버깅할 목적으로 사용한다. */
int lock_depth; /* 현재 프로세스가 어디에서 lock이 걸렸는지 나타낸다 Lock depth */

/* offset 32 begins here on 32-bit platforms. We keep all fields in a single cacheline that are needed for the goodness() loop in schedule(). */
long counter;
long nice;
unsigned long policy;
struct mm_struct mm;
int has_cpu, processor;
unsigned long cpus_allowed;
/* (only the 'next' pointer fits into the cacheline, but that's just fine.) */
struct list_head run_list; /* 실행 큐 (runqueue) */
unsigned long sleep_time;

/* 커널 내에 존재하는 모든 테스크들을 이중 링크드 리스트로 구현한다. 이 이중 링크드 리스트에 첫번째 테크스는
init 테스크 (스와퍼 테스크)이다. */
struct task_struct *next_task, *prev_task;
struct mm_struct *active_mm;

/* task state */
/* 리눅스에서 지원하는 이진 파일 포맷 중에 어떤 이진 파일 포맷을 실행하는지 나타낸다. */
struct linux_binfmt *binfmt;
int exit_code, exit_signal; /* 프로세스 종료 시에 돌려줄 값과 보내햐 할 시그널을 갖는다. */
int pdeath_signal; /* The signal sent when the parent dies */

unsigned long personality; /* 현재 프로세스가 실행되기 위해 에뮬레이션할 시스템을 나타낸다. */
int dumpable:1; /* 현재 프로세스를 덤프할 수 있는지 나타낸다. */
int did_exec:1; /* 시스템 콜을 호출했는지를 설정할 수 있다. */

/* typedef __kernel_pid_t pid_t ; typedef int __kernel_pid_t; */
pid_t pid;
pid_t pgrp;
pid_t tty_old_pgrp;
pid_t session;
pid_t tgid; /* 스레드 그룹 내에 첫 번째 경량 프로세스의 PID */

/* boolean value for session group leader */
int leader;

/* pointers to (original) parent process, youngest child, younger sibling, older sibling,
respectively. (p->father can be replaced with p->p_pptr->pid) */
struct task_struct *p_opptr, *p_pptr, *p_cptr, *p_ysptr, *p_osptr;

/* 같은 스레드 그룹에 들어 있는 모든 경량 프로세스의 디스크립터를 이중 연결 리스트로 구현한다. */
struct list_head thread_group;

/* PID hash table linkage.
PID를 가지고 찾고자 하는 프로세스를 쉽게 찾을 수 있는 hash 테이블에 대한 포인터를 pidhash_next와
pidhash_pprev에 저장한다. 프로세스는 생성될 때 PID를 부여 받으며, 이를 이용해서 프로세스의 검색을
용이하게 하는 할 수 있는 해쉬 테이블에 저장된다. */
struct task_struct *pidhash_next;
struct task_struct **pidhash_pprev;

/* 자식 프로세스가 종료할 때까지 기다리는 wait_queue를 연결하기 위해 사용한다. */
wait_queue_head_t wait_chldexit; /* for wait4() */
struct semaphore *vfork_sem; /* vfork 함수를 호출했을 때 사용되는 세마포 값이다. for vfork() */

unsigned long rt_priority; /* 프로세스에게 주어진 정적인 우선 순위 */

/* 타이머 사용과 관련된 데이터를 저장한다. it_real_value, it_prof_value, it_virt_value 필드는 타이머가 작동하기 전에
얼마나 시간이 경과해야 할 지를 나타내는 tick 값이다. 그리고 it_real_incr, it_prof_incr, it_virt_incr 필드는 타이머를
초기화하는데 사용된다. */
unsigned long it_real_value, it_prof_value, it_virt_value;
unsigned long it_real_incr, it_prof_incr, it_virt_incr;
struct timer_list real_timer; /* 실시간 인터벌 타이머 구현에 사용된다. */
struct tms times; /* 프로세스 회계에 사용된다. */
unsigned long start_time; /* 프로세스가 실행된 시정을 나타낸다. */

/* 각 아래 필드는 CPU마다 실행된 사용자 타임과 시스템 타임을 갖는다. */
long per_cpu_utime[NR_CPUS], per_cpu_stime[NR_CPUS];

/* mm fault and swap info: this can arguably be seen as either mm-specific or thread-specific
min_fit, maj_fit 필드는 메모리 트랩이 발생된 횟수를 나타낸 것으로 각각이 페이지 로드가 없이 처리된 횟수와 디스크로부터
하나의 페이지를 로드하는 동안에 처리된 수를 나타낸다. cmin_fit, cmaj_fit 필드는 자식 프로세스에 대한 경우이다.
nswap 필드는 프로세스 페이지가 스왑 영역에 들어있는 수를, cnswap 필드는 자식 프로세스의 페이지가 스왑 영역에 들어
있는 수를 각각 나타낸다. */
unsigned long min_flt, maj_flt, nswap, cmin_flt, cmaj_flt, cnswap;
int swappable:1; /* 프로세스가 스왑될 수 있는 가를 나타낸다. */

/* process credentials
uid : 사용자 ID (User ID) euid : 유효 사용자 ID (Effective User ID)
suid : 보관된 사용자 ID (Saved User ID) fsuid : 파일 시스템 사용자 ID (File System User ID)
gid : 그룹 ID (Group ID) egid : 유효 그룹 ID (Effective Group ID)
sgid : 보관된 그룹 ID (Saved Group ID) fsgid : 파일 시스템 그룹 ID (File System Group ID)*/
uid_t uid,euid,suid,fsuid;
gid_t gid,egid,sgid,fsgid;
int ngroups; /* 프로세스가 속한 그룹에 개수 */
gid_t groups[NGROUPS]; /* 프로세스가 속한 그룹 */


/* 현재 프로세스가 가지는 capability를 나타낸다. */
kernel_cap_t cap_effective, cap_inheritable, cap_permitted;
int keep_capabilities:1; /* 현재 프로세스가 어떤 capability를 갖는지 나타낸다 */
/* 사용자 정보 중에 얼마나 많은 프로세스를 사용자가 가지는지, 그리고 얼마나 많은 열린 파일들을 가지는지 등을
나타낸다. */
struct user_struct user;

/* limits */
struct rlimit rlim[RLIM_NLIMITS]; /* 프로세스의 자원 사용 상태를 나타낸다. */
unsigned short used_math; /* 프로세서가 수치 보조 프로세서를 사용하는지 나타낸다. */
char comm[16]; /* 현재 실행 중인 프로세서 명을 저장한다. */
/* file system info */
int link_count; /* 실행하기 위해 파일 이름의 검색에 사용했던 심볼릭 링크 수 */
struct tty_struct *tty; /* 프로세스에 할당된 터미널을 나타내는 데이터 구조체 포인터 */
unsigned int locks; /* 파일에 락이 얼마나 걸었는지 How many file locks are being held */
/* ipc stuff : semundo, semsleeping 필드는 프로세스가 세마포 자원을 사용할 때 사용한다. */
struct sem_undo *semundo; /* 현재 수면 상태에 있는 프로세스들의 세마포 대기 큐를 나타낸다. */
struct sem_queue semsleeping; /* 세마포 리스트 이다. */

/* 프로세서의 레지스터 값을 저장한다. (하드웨어 컨텍스트 저장) : CPU-specific state of this task */
struct thread_struct thread;

struct fs_struct *fs; /* 파일에 대한 접근시 확인할 정보를 저장 : filesystem information */
/* 프로세스에 의해 열려진 파일 기술자에 대한 포인터 이다. open file information */
struct files_struct *files;

/* signal handlers */
spinlock_t sigmask_lock; /* 시그널과 관련된 연산에 적용되는 락. Protects signal and blocked*/
struct signal_struct sig; /* 시그널 구조체를 가리키는 포인터이다. */
/* 블록킹된 시그널은 프로세스로 전달되지 않으며, 처리를 기다리고 있는 시그널은 나중에 프로세스가 실행되는 시점에
처리된다. */

sigset_t blocked; /* 마스킹 된 시그널을 나타낸다. */
struct sigpending pending; /* 처리를 기다리고 있는 시그널에 대한 리스트를 나타낸다. */
unsigned long sas_ss_sp; /* 시그널과 관련된 스택을 가리킨다. */
size_t sas_ss_size; /* 스택의 크기이다. */
int (*notifier)(void *priv); /* 기다리고 있는 시그널이 도착했음을 알려주는 함수 포인터이다. */
void notifier_data; /* notifier_data를 넘겨 받아 처리한다. */
sigset_t *notifier_mask; /* 관심을 가진 시그널은 notifier_mask를 통해 알 수 있다. */

/* Thread group tracking
fork 함수호출은 self_exec_id를 생성되는 프로세스의 parent_exec_id로 받게 되며, exit 함수호출에 이 곳에 저장된
값들을 확인해서 어떤 시그널들을 전달재줄 지를 결정한다. */
u32 parent_exec_id; /* 부모의 exec_id이다 */
u32 self_exec_id; /* 자식의 exec_id이다 */

/* Protection of (de-)allocation: mm, files, fs, tty
메모리 및 파일, 또는 파일 시스템이나 터미널에 대한 할당이나 제거될 때에 사용되는 락이다. */
spinlock_t alloc_lock;

};