Processes and Process Scheduling

  • Upload
    srinu63

  • View
    220

  • Download
    0

Embed Size (px)

Citation preview

  • 8/14/2019 Processes and Process Scheduling

    1/27

    Processes and Scheduling

  • 8/14/2019 Processes and Process Scheduling

    2/27

    Agenda

    Processes Process Descriptor and Task Structure

    Process Creation

    Kernel Implementation of Threads

    Process Termination

    Process Scheduling

    Processor Bound and I/O Bound

    Policy

    Linux Scheduling Algorithm

    Preemption and Context Switching

    System Calls

  • 8/14/2019 Processes and Process Scheduling

    3/27

    Process

    The process is one of the fundamental abstractions inUnix operating systems

    Processes provide two virtualizations: a virtualized

    processor and virtual memory.

    Linux has a unique implementation of threads: It does notdifferentiate between threads and processes.

    Thread is just a special kind of process.

    The system identifies processes by a unique process

    identification value or PID.

  • 8/14/2019 Processes and Process Scheduling

    4/27

    Process Descriptor and Task Structure

    The kernel stores the list of processes in a circular doubly

    linked list called the task list

    Each element in the task list is a process descriptor of the

    type struct task_struct. ().

    The process descriptor contains all the information about

    a specific process.

    The task_struct structure is allocated via the slab allocator

    to provide object reuse

  • 8/14/2019 Processes and Process Scheduling

    5/27

    Process Descriptor and Task Structure

    struct thread_info, was created that lives at bottom ofkernel stack which in turn points to task_struct

    Process descriptor of the currently executing task is

    accessed via the current macro.

    current->pid to retrieve the pid

  • 8/14/2019 Processes and Process Scheduling

    6/27

    Task Structure

    Process attributes

    Process relationships

    Process memory space

    File management

    Signal management

    Process credentials

    Resource limits

    Scheduling related fields

  • 8/14/2019 Processes and Process Scheduling

    7/27

    Process Kernel Stack and Process Descriptor

  • 8/14/2019 Processes and Process Scheduling

    8/27

    Process States

  • 8/14/2019 Processes and Process Scheduling

    9/27

    Process Creation

    fork() creates a child process that is a copy of the currenttask

    Differs from the parent only in its PID and PPID

    exec(), loads a new executable into the address space

    and begins executing it. The combination of fork() followed by exec() is similar to

    the single function most operating systems provide.

  • 8/14/2019 Processes and Process Scheduling

    10/27

    Process Creation

    Copy-On-Write

    Linux implements fork() via the clone() system call.

    The vfork() system call has the same effect as fork(),

    except that the page table entries of the parent process

    are not copied.

  • 8/14/2019 Processes and Process Scheduling

    11/27

    Process Creation

    Thread

    clone(CLONE_VM | CLONE_FS | CLONE_FILES |

    CLONE_SIGHAND, 0);

    Process with fork( )clone(SIGCHLD, 0);

    Process with vfork( )

    clone(CLONE_VFORK | CLONE_VM | SIGCHLD, 0);

  • 8/14/2019 Processes and Process Scheduling

    12/27

    Kernel Threads

    Kernel to perform some operations inbackground

    Address space pointer is null

    To create a new thread kernel_thread

    function is used, this in turn uses clone

    system call

  • 8/14/2019 Processes and Process Scheduling

    13/27

    Process Destruction

    process destruction occurs when the process calls theexit() system call

  • 8/14/2019 Processes and Process Scheduling

    14/27

    Processor-bound and I/O-bound

    I/O bound process spends much of its time submitting andwaiting on I/O requests

    Processor-bound process spend much of their time executing

    code

    Scheduling should satisfy both the processes

  • 8/14/2019 Processes and Process Scheduling

    15/27

    Process Priority

    Dynamic priority-based scheduling

    The Linux kernel implements two separate priority ranges.

    The first is the nice value, a number from -20 to +19 with a

    default of 0. The second range is the real-time priority. Default range

    from 0 to 99

    Dynamic Priority is based on static priority and interactivity

  • 8/14/2019 Processes and Process Scheduling

    16/27

    Process Scheduling

    Implement fully O(1) scheduling.

    Provide good interactive performance.

    The basic data structure in the scheduler is the runqueue.

    The runqueue is the list of runnable processes on a givenprocessor

  • 8/14/2019 Processes and Process Scheduling

    17/27

    Process Scheduling

    Each runqueue contains two priority arrays, the active and

    the expired array.

    Priority arrays are the data structures that provide O(1)

  • 8/14/2019 Processes and Process Scheduling

    18/27

    Process Scheduling

  • 8/14/2019 Processes and Process Scheduling

    19/27

    Priority Arrays in a Runqueue

  • 8/14/2019 Processes and Process Scheduling

    20/27

    Preemption and Context Switching

    User preemption

    Kernel preemption

  • 8/14/2019 Processes and Process Scheduling

    21/27

    System Calls

    System calls provide a layer between the hardware and

    user-space processes.

    system calls ensure system security and stability

    A single common layer between user-space and the restof the system allows for the virtualized system provided to

    processes

  • 8/14/2019 Processes and Process Scheduling

    22/27

    Application, C Library and Kernel

  • 8/14/2019 Processes and Process Scheduling

    23/27

    System Call Handling

    User-space applications cannot execute kernel codedirectly

    The mechanism to signal the kernel is a softwareinterrupt: Incur an exception and then the system willswitch to kernel mode and execute the exception

    handler. Each system call is assigned a syscall number

    The kernel keeps a list of all registered system callsin the system call table, stored in sys_call_table.

    On x86, the syscall number is fed to the kernel via theeax register

    The system_call() function checks the validity of thegiven system call number

  • 8/14/2019 Processes and Process Scheduling

    24/27

    System Call Handling

  • 8/14/2019 Processes and Process Scheduling

    25/27

    System Call Handling

    System call parameters are stored in registers. On x86,the registers ebx, ecx, edx, esi, and edi contain, in order,

    the first five arguments.

    In the unlikely case of six or more arguments, a single

    register is used to hold a pointer to user-space where all

    the parameters are stored.

    The return value is sent to user-space also via register.

    On x86, it is written into the eax register.

  • 8/14/2019 Processes and Process Scheduling

    26/27

    Verifying the Parameters

    System calls must carefully verify all their parameters to

    ensure that they are valid and legal. File I/O syscalls must check whether the file descriptor is

    valid. Process-related functions must check whether theprovided PID is valid.

    For writing into user-space, the method copy_to_user() isprovided.

    For reading from user-space, the methodcopy_from_user() is provided

    The kernel is in process context during the execution of a

    system call. The current pointer points to the current task,which is the process that issued the syscall.

  • 8/14/2019 Processes and Process Scheduling

    27/27

    Thank You