task_struct 분석

EEEFFEE·2024년 1월 23일

crash utility

목록 보기
1/5
post-thumbnail

24.01.23 최초 작성

  • bt <task_struct 시작 주소> : 콜 스택을 확인할 수 있음

  • ps : 프로세스 목록 확인할 수 있음

  • struct -o 옵션 : 각 구조체 필드의 주소 확인 가능

1. task_struct

  • struct task_struct[.조회하고자 하는 자료구조] <task_struct 시작 주소> : 해당 task_struct를 가진 프로세스의 정보를 나타냄

  • struct task_struct.flags <task_struct 시작 주소> : 현재 프로세스의 동작 상태, 속성 정보를 나타냄


// /include/linux/sched.h

#define TASK_RUNNING			0x0000				//실행 대기 상태
#define TASK_INTERRUPTIBLE		0x0001				//sleep 상태
#define TASK_UNINTERRUPTIBLE		0x0002			//sleep 상태
#define __TASK_STOPPED			0x0004
#define __TASK_TRACED			0x0008
/* Used in tsk->exit_state: */
#define EXIT_DEAD			0x0010
#define EXIT_ZOMBIE			0x0020
#define EXIT_TRACE			(EXIT_ZOMBIE | EXIT_DEAD)
...

  • struct task_struct.stack <task_struct 시작 주소> : 해당 프로세스의 stack영역 시작 주소

  • struct task_struct.prio <task_struct 시작 주소> : 해당 프로세스의 실행 우선순위를 나타냄

  • sched_class : 스케줄 정책을 나타냄


//	sched_class 설정 루틴
//	kernel/sched/core.c
int sched_fork(unsigned long clone_flags, struct task_struct *p)
{
	...
    if (dl_prio(p->prio))
		return -EAGAIN;
	else if (rt_prio(p->prio))
		p->sched_class = &rt_sched_class;
	else
		p->sched_class = &fair_sched_class;
        
    ...
}

  • struct task_struct.tasks <task_struct 시작 주소> : linked list로 구현되었으며 다음 실행될 프로세스의 시작 주소를 나타냄

//	task
//	kernel/fork.c
static __latent_entropy struct task_struct *copy_process(
					struct pid *pid,
					int trace,
					int node,
					struct kernel_clone_args *args)
{
	...
    
    list_add_tail_rcu(&p->tasks, &init_task.tasks);
    
    ...
}

  • struct task_struct.mm <task_struct 시작 주소> : 가상 주소 정보를 담고있는 필드

  • struct task_struct.comm <task_struct 시작 주소> : 해당 프로세스의 이름을 나타냄

  • struct task_struct.files <task_struct 시작 주소> : 파일 디스크립터를 관리하는fd_array의 시작 주소를 나타냄

  • struct task_struct.[signal/sighand] <task_struct 시작 주소> : 프로세스가 시그널을 받아 저장하는 signal구조체의 시작 주소와 이후 정보를 받아 이를 처리하는 루틴의 시작 주소인 sighand의 시작 주소를 나타냄

  • struct task_struct.thread.cpu_context <task_struct 시작 주소> : 해당 프로세스의 컨텍스트 정보를 나타냄

  • struct task_struct.[stime/utime] <task_struct 시작 주소> : 해당 프로세스가 커널 공간에서 실행된 시간(stime)과 유저 공간에서 실행된 시간(utime)을 나타냄

  • `` :


0개의 댓글