DOC PREVIEW
Columbia COMS W4118 - Linux

This preview shows page 1-2-14-15-29-30 out of 30 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 30 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 30 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 30 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 30 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 30 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 30 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 30 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

W4118 Operating Systems Instructor: Junfeng YangOutline Linux process overview Linux process data structures Linux process operationsFinding process information ps top For each process, there is a corresponding directory /proc/<pid> to store this process information in the /proc pseudo file systemHeader filesinclude/linux/sched.h – declarations for most process data structuresinclude/linux/wait.h – declarations for wait queuesinclude/asm-i386/system.h – architecture-dependent declarationsSource files kernel/sched.c – process scheduling routines kernel/signal.c – signal handling routines kernel/fork.c – process/thread creation routines kernel/exit.c – process exit routines fs/exec.c – executing program arch/i386/kernel/entry.S – kernel entry points arch/i386/kernel/process.c – architecture-dependent process routinesProcess-related filesKernel address space Kernel needs work space as wellStore kernel code, data, heap, and stack• E.g., process control blocksMust be protected from user processes Can give kernel its own address space Problem: switching address space is costly Solution: map kernel address space into process address spaceLinux process address spaceUser spaceKernel spaceUser-mode stack-areaProcess code and datakernel modeuser modeKernel space is also mapped into user space  from user mode to kernel mode, no need to switch address spacesProtection?Kernel space is only accessible when mode bit = 0Shared runtime-libraries03G4Gprocess descriptorandkernel-mode stackLinux: processes or threads? Linux uses a neutral term: tasksTasks represent both processes and threadsWhen processes trap into the kernel, they share the Linux kernel’s address space  kernel threadsOutline Linux process overview Linux process data structures Linux process operationsLinux task data structures  task_struct: process control block thread_info: low level task data, directly accessed from entry.S kernel stack: work space for systems calls (the kernel executes on the user process’s behalf) or interrupt handlers Task queues: queues that chain tasks togetherProcess Control Block in Linux task_struct (process descriptor in ULK)include/linux/sched.hEach task has a unique task_structProcess statesstate: what state a process is inTASK_RUNNING – the thread is running on the CPU or is waiting to runTASK_INTERRUPTIBLE – the thread is sleeping and can be awoken by a signal (EINTR)TASK_UNINTE RRUPTIBLE – the thread is sleeping and cannot be awakened by a signalTASK_STOPPED – the process has been stopped by a signal or by a debuggerTASK_TRACED – the process is being traced via the ptracesystem callexit_state: how a process exitedEXIT_ZOMBI E – the process is exiting but has not yet been waited for by its parentEXIT_DEAD – the process has exited and has been waited forHardware state Thread: thread_struct – hardware state, e.g., registers x86 hardware state is defined in include/asm-i386/processor.hProcess scheduling prio: priority of the process Static_prio, run_list, array, sleep_avg, timestamp, last_ran, time_slice, …More on Linux scheduling laterProcess IDs process ID: pid thread group ID: tgidpid of first thread in processgetpid() returns this ID, so all threads in a process share the same process ID many system calls identify a process by its PIDLinux kernel uses pidhash to efficiently find processes by pidssee include/linux/pid.h, kernel/pid.cProcess Relationships Processes are related: children, siblingParent/child (fork()), siblingsPossible to "re-parent"• Parent vs. original parentParent can "wait" for child to terminate Process groups: signal_struct->pgrpPossible to send signals to all members Sessions: signal_struct->sessionProcesses related to loginOther PCB data structures user: user_struct – per-user information (for example, number of current processes) mm, active_mm: mm_struct – memory areas for the process (address space) fs: fs_struct – current and root directories associated with the process files: files_struct – file descriptors for the process signal: signal_struct – signal structures associated with the processthread_info include/asm-i386/thread_info.h low level task data, directly accessed from entry.S current_thread_info: get current thread_infostruct from Ckernel stack Each process in Linux has two stacks, a user stack and a kernel stack (8KB by default)Kernel stack can only be accessed in kernel modeKernel code runs on kernel stack Why not reuse user-space stack?homeworkFinding kernel stack (on x86)CPU0trGlobal Descriptor Table8-KBTask’s kernel-stackCPU0kern stack topespUpon intr, h/w retrieves kernel stack top and load it into %esp, also pushes previous %esp &%eip on kernel stackChanges on each context switch (__switch_to inarch/i386/kernel/process.c)initialized in startup_32 in arch/i386/boot/compressed/head.SConnections between task_struct and kernel stack Linux uses part of a task’s kernel-stack to store a structure thread_infothread_info and task_struct contain pointers to each otherTask’s kernel-stackTask’s thread-infoTask’sprocess-descriptorstruct task_struct8-KB8KB aligned0xe800e0000xe8010000How to find thread_info from kernel stack?movl $0xFFFFE000, %eaxandl %esp, %eax (mask out last 13 bits)Task’s kernel-stackTask’s thread-infoTask’sprocess-descriptorstruct task_struct8-KB8KB aligned0xe800e000esp0xe8010000How Linux manages processes Linux uses multiple queues to manage processesQueue for all tasksQueue for “running” tasks Queues for tasks that temporarily are “blocked”while waiting for a particular event to occur These queues are implemented using doubly-linked list (struct list_head in include/linux/list.h)Some tasks are ‘ready-to-run’Those tasks that are ready-to-run comprise a sub-list of all the tasks, and they are arranged on a queue known as the ‘run-queue’(struct runqueue in kernel/sched.c)Those tasks that are blocked while awaiting a specific event to occurare put on alternative sub-lists, called ‘wait queues’, associated withthe particular event(s) that will allow a blocked task to be unblocked (wait_queue_t in include/linux/wait.h and kernel/wait.c)run_queueinit_task listKernel Wait


View Full Document

Columbia COMS W4118 - Linux

Download Linux
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Linux and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Linux 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?