Www.Notes for human resource management in a business context 2/e

Classified in Computers

Written at on English with a size of 22.48 KB.

1) What is a process?

Program in execution
2) What are Lightweight Processes in Linux?

Processes which can offer better support for Multithreaded applications.
3) Explain what is meant by multithreaded application. Describe how Multithreaded
Applications are implemented in linux. Give three examples of POSIX-compliant Pthread

A straightforward way to implement Multithreaded applications is to associate a lightweight process with each thread.

In this way, the threads can access the same Set of application data structures by simply sharing the same memory address Space, the same set of open files, and so on; at the same time, each thread can Be scheduled independently by the kernel so that one may sleep while another Remains runnable.

Examples of POSIX-compliant pthread libraries That use Linux's lightweight processes are LinuxThreads, Native POSIX Thread Library (NPTL), and IBM's Next Generation Posix Threading
Package (NGPT).
4) Describe thread group in linux.

In Linux a thread group is basically a set of Lightweight processes that implement a multithreaded application and act as a Whole with regards to some system calls such as getpid( ), kill( ), and _exit( )
5) What is meant by process descriptor and explain the role of the process Descriptor?

Process descriptor uses to manage processes. It Must know, the process's priority, whether it is running on a CPU or blocked on An event, what address space has been assigned to it, which files
It is allowed to address, and this kind of all information related to a single Process.
6) With the help of a schematic, describe the Linux process descriptor struct Task_struct.

7) List the seven possible process states in Linux OS and explain.

8) Describe the following process states in linux :
TASK_RUNNING The process is either executing on a CPU or waiting to be Executed.
TASK_INTERRUPTIBLE The process is suspended (sleeping) until some condition Becomes true. Raising a hardware interrupt, releasing a system resource the Process is waiting for, or delivering a signal are examples of conditions that Might wake up the process (put its state back to TASK_RUNNING)
TASK_UNINTERRUPTIBLE Like TASK_INTERRUPTIBLE, except that delivering a Signal to the sleeping process leaves its state unchanged.
TASK_STOPPED Process execution has been stopped; the process enters this State after receiving a SIGSTOP, SIGTSTP, SIGTTIN, or SIGTTOU signal.
TASK_TRACED Process execution has been stopped by a debugger. When a process Is being monitored by another (such as when a debugger executes a ptrace( ) System call to monitor a test program), each signal may put the process in the TASK_TRACED state.
EXIT_ZOMBIE ­Process execution is Terminated, but the parent process has not yet issued a wait4( ) or waitpid( ) System call to return information about the dead process.­Before the wait( )-like call is issued, the Kernel cannot discard the data contained in the dead process descriptor because The parent might need it. ­There are other wait( ) -like library functions, such as wait3( ) and wait( ), but in Linux they are Implemented by means of the wait4( ) and waitpid( ) system calls.
EXIT_DEAD ­The final state: the Process is being removed by the system because the parent process has just Issued a wait4( ) or waitpid( ) system call for it. ­Changing its state from EXIT_ZOMBIE to EXIT_DEAD avoids race conditions due to other threads of execution that execute Wait( )- like calls on the same process.
9) State the purpose of TASK_UNINTERRUPTIBLE state in linux process.

Like TASK_INTERRUPTIBLE, except that delivering A signal to the sleeping process leaves its state unchanged
10) State the two approaches used by kernel to identify a process. set_task_state And

11) What is meant by PID? Why is it required? Process ID, to identify Processes by means of a number
12) What is the upper limit on the PID values in 32-bit architectures? 32,767
13) What is the upper limit on the PID values in 64-bit architectures? 4,194,303.
14) State the purpose of a pidmap_array bitmap in linux. Indicate the size of The pidmap_array
Bitmap. To denote which are the PIDs currently assigned and which are the Free ones. 32,768 bits
15) Indicate which lightweight process becomes by default the thread group Leader. What is
The PID assigned to the thread group?  The Identifier shared by the threads is the PID of the thread group leader , that Is, the PID of the first lightweight process in the group; it is stored in the Tgid field of the process descriptors
16) Since kernel must be able to handle many processes at the same time, Hence process
Descriptors are stored in dynamic memory rather than in the memory area Permanently
Assigned to the kernel.
17) Describe the two different data structures assigned to every process by the Kernel in a
Single per-process memory area. Indicate the length of this memory area and explain the
Data structures stored in this memory area with the help of a diagram showing Clearing
Both these data structures. small data structure linked to the Process descriptor, namely the thread_info structure, and the Kernel Mode Process stack. The length of this memory area is usually 8,192 bytes (two page Frames).
18) Explain the purpose of the following two different data structures assigned To every
Process by the kernel in a single per-process memory area. Indicate the size of Each of
These data structures

a) Thread_info Structure stack(may use more than 8kB stack to avoid overflow) . in the 80x86 architecture the kernel can be configured at compilation time so that the Memory area including stack and thread_info structure spans a single page frame (4,096 bytes).

b) kernel mode Process stack(uses only 8kB) A process in Kernel Mode accesses a stack Contained in the kernel data segment, which is different from the stack used by The process in User Mode. Because kernel control paths make little use of the Stack, only a few thousand bytes of kernel stack are required. Therefore, 8 KB Is ample space for the stack and the tHRead_info structure.
19) State the key benefit in terms of efficiency offered by the kernel in Providing a close association between the thread_info structure and the kernel Mode stack.

Because the thread_info structure is 52 bytes Long, the kernel stack can expand up to 8,140 bytes. The kernel can easily Obtain the address of the thread_info structure of the process currently Running on a CPU from the value of the esp register. In fact, if the thread_union Structure is 8 KB (213 bytes) long, the kernel masks out the 13 least Significant bits of esp to obtain the base address of the thread_info Structure;  on the other hand, if the Thread_union structure is 4 KB long, the kernel masks out the 12 least Significant bits of esp.
20) State the purpose of current macro in linux.  Most often the kernel needs the address of the Process descriptor rather than the address of the thread_info structure. • To Get the process descriptor pointer of the process currently running on a CPU, The kernel makes use of the current macro, which is essentially equivalent to Current_thread_info( )->task • The current macro often appears in kernel Code as a prefix to fields of the process descriptor. For example, current->pid Returns the process ID of the process currently running on the CPU.

21) Explain what is meant by process list. Explain how process list is implemented in linux.

In Linux PROCESS LIST is implemented as a Doubly linked list, a list that links together all existing process descriptors. The head of the process list is the init_task task_struct descriptor; it is the Process descriptor of the so-called process 0 or swapper

 The tasks->prev field of init_task points To the tasks field of the process descriptor inserted last in the list.

 The SET_LINKS and REMOVE_LINKS macros are Used to insert and to remove a process descriptor in the process list, Respectively.

22) With the help of a block diagram, show the Special data structures used to implement the

process list. Also indicate the processes the first Two nodes in the data structure point to.

23) Explain how runqueue is implemented in linux to achieve scheduler speedup To select the

Earlier Linux versions put all runnable Processes in the same list called runqueue.
Best runnable process in constant time.
24) With the help of a figure, illustrate the relationship between parent and Siblings of a group
Of processes. Process P0 successively created P1, P2, and P3. Process P3, in Turn, created
Process P4

25) Write short notes on pid hash table and chained lists. To speed up the Search, four hash tables have been introduced. Simply because the Process descriptor includes fields that represent different types of PID, and Each type of PID requires its own hash table.

Linux uses chaining to handle colliding PIDs; Each table entry is the head of a doubly linked list of colliding process Descriptors.

Hashing with chaining is preferable to a linear Transformation from PIDs to table indexes because at any given instance, the Number of processes in the system is usually far below 32,768 (the maximum Number of allowed PIDs)
26) With the help of block diagram, describe pid hash table and chained lists.

27) What are the four PID hash tables used in linux. Why are they required?

28) With the help of a block diagram, describe the four hash tables and show How these data
Structures are implemented showing clearly the chained lists and processes in Each group.

29) Explain the purpose of wait queue in linux.

the process state does not provide enough Information to retrieve the process quickly, so it is necessary to introduce Additional lists of processes called wait queues. A wait queue represents a set Of sleeping processes, which are woken up by the kernel when some condition Becomes true
30) Describe runqueue and wait queues in Linux. The runqueue lists group all Processes in a TASK_RUNNING state. ­When it comes to grouping processes in other States, the various states call for different types of treatment, with Linux Opting for one of the choices shown in the following list.
31) Indicate the three important uses of the wait queues in the kernel. interrupt Handling, process
Synchronization, and timing.

32) Describe how wait queues are implemented in linux by providing the Following two data
Structures - struct __wait_queue_head and struct wait_queue and clearly Indicating
The purpose of various fields in these data structures.

1.Each wait queue is identified by a wait queue Head, a data structure of type wait_queue_head_t:

Struct _ _wait_queue_head {
Spinlock_t lock;
Struct list_head task_list; };
Typedef struct __wait_queue_head wait_queue_head_t;

­Because wait queues are modified by interrupt Handlers as well as by major kernel functions, the doubly linked lists must be Protected from concurrent accesses, which could induce unpredictable
Results. ­Synchronization is achieved by the lock spin Lock in the wait queue head. ­The task_list field is the head of the list of Waiting processes

2.Elements of a wait queue list are of type Wait_queue_t:

Struct __wait_queue {
Unsigned int flags;
Struct task_struct * task;
Wait_queue_func_t func;
Struct list_head task_list; };
Typedef struct __wait_queue wait_queue_t;

­Each element in the wait queue list represents A sleeping process, which is waiting for some event to occur; its descriptor Address is stored in the task field.
­The task_list field contains the pointers that Link this element to the list of processes waiting for the same event.
­flags field indicate kinds of sleeping process
­func field specifies how the processes sleeping In the wait queue should be woken up.

33) What is meant by “thundering herd” problem. Explain how it is tackled. multiple Processes are wakened only to race for a resource that can be accessed by one Of them, with the result that remaining processes must once more be put back to Sleep
34) What are the two kinds of sleeping processes in wait queue. Why do you Require this

Exclusive processes (denoted by the value 1 in the flags field of the Corresponding wait queue
Element) are selectively woken up by the kernel

Non-exclusive processes (denoted by the value
0 in the flags field) are always woken up by the kernel when the event occurs
35) Explain process Resource limits in Linux and list the various resource Limits specified.

Each process has an associated set of resource limits , which specify The amount of system resources it can use.
­These limits keep a user from overwhelming the System (its CPU, disk space, and so on).
36) State the purpose of the following commands in Unix/linux
A) ulimit -Ha

b) ulimit -Sa

c) getconf -a

d) getconf PAGE_SIZE
37) Describe Process switch or context switch or task switch in linux.

To control the execution of processes, the kernel must be able to Suspend the execution of the process running on the CPU and resume the Execution of some other process previously suspended. This activity goes Variously by the names process switch, task switch, or context switch
38) Explain Hardware context in Linux. The set of data that must be loaded Into the registers before the process resumes its execution on the CPU is Called the hardware context. In Linux, a part of the hardware context of a Process is stored in the process descriptor, while the remaining part is saved In the Kernel Mode stack.
39) Write short notes on the following:
A) Task State Segment Linux uses hardware support offered by the 80x86 Architecture and performs a process switch through jmp instruction to the Selector of the Task State Segment Descriptor of the next process. The 80x86 architecture includes a specific Segment type called the Task State Segment (TSS), to store hardware contexts

b) Thread field each process descriptor includes A field called thread of type thread_struct, in which the kernel saves the Hardware context whenever the process is being switched out.
40) Describe how kernel performs a process switch using schedule() function.

1.Switching the Page Global Directory to install a new address space;
2.Switching The Kernel Mode stack and the hardware context, which provides all the Information needed by the kernel to execute the new process, including the CPU Registers.
41) Explain three different mechanismsintroduced by modern Unix kernels to solve the
Problem of duplicating address space. Also indicate the system call associated With each
One of these mechanisms to create a process.

1.Copy On Write technique - allows both the parent and the child to read The same physical
Pages. Whenever either one tries to write on a physical page, the kernel copies Its contents into a new physical page that is assignedto the writing process.
2. Lightweight Processes - allow both the parent and the child to share many Per-process
Kernel data structures, such as the paging tables (and therefore the entire User Mode address space), the open file tables, and the signal dispositions.
3. vfork( ) system call - creates a process that shares the memory Address space of its parent.
To prevent the parent from overwriting data needed by the child, the parent's Execution is blocked until the child exits or executes a new program.
42) State the three system callsused to create a process. Why are these system calls Required?

clone( ), fork( ), and vfork( ) System Calls Lightweight processes are Created in Linux by using a function named clone( )

43) Write the system call used to create a Lightweight process in linux.

Lightweight processes are created in Linux by using a function named Clone( ), which uses the following parameters:

fn Specifies a function to be executed by the new process; when the Function returns, the child terminates. The function returns an integer, which Represents the exit code for the child process.

Arg Points to data passed to the fn( ) function

Flags Miscellaneous information. The low byte specifies the signal number to Be sent to the parent process when the child terminates; the SIGCHLD signal is Generally selected.

child_stack Specifies the User Mode stack pointer to be assigned to the esp register Of the child process. The invoking process (the parent) should always allocate A new stack for the child.

Tls Specifies the address of a data structure that defines a Thread Local Storage segment for the new lightweight process. Meaningful only if the CLONE_SETTLS flag is set.

ptid Specifies the address of a User Mode variable of the parent process that Will hold the PID of the new lightweight process. Meaningful only if the CLONE_PARENT_SETTID flag is set.

Ctid Specifies the address of a User Mode variable of the new lightweight Process that will hold the PID of such process. Meaningful only if the CLONE_CHILD_SETTID flag is set.
44) Write short notes on
A) Process 0 The ancestor of all processes, called process 0, the idle Process, or, for historical reasons, the swapper process, is a kernel thread Created from scratch during the initialization phase of Linux

b) Process 1 The kernel thread created by process 0 executes the init( ) function, which in turn completes the initialization of The kernel. Then init( ) invokes the execve( ) system call to load the Executable program init.
45) Describe the operations performed by the following functions in linux :
A) do_fork()makes use of an auxiliary function called copy_process() to set Up the process descriptor and any other kernel data structure required for Child's execution.

 b) Copy_process()The swapper process running on CPU 0 initializes the kernel Data structures, then enables the other CPUs and creates the additional swapper Processes by means of the copy_process( ) function passing to it the value 0 as The new PID.
46) What are kernel threads? Explain how kernel threads are created in linux. Kernel Threads run only in Kernel Mode, while regular processes run alternatively in Kernel Mode and in User Mode. It receives as parameters the address of the Kernel function to be executed (fn), the argument to be passed to that function (arg), and a set of clone flags (flags). This function essentially invokes Do_fork( )
47) State the purpose of following functions in linux.
A) kernel_thread( )function creates a new kernel thread.

b) copy_process()function passing to it the value 0 as the new PID.

c) exit()system call, which terminates a single Process, regardless of any other process in the thread group of the victim

d) exit_group()system call, which terminates a Full thread group, that is, a whole multithreaded application.
48) Describe how processes are created and terminated/destroyed in Linux?

 processes are created by using a Function named clone( ) and terminated/destroyed by _exit( )
49) What is orphan process? How orphan process is handled in linux to eliminate Memory leak?

Orphan processes is to become children of the init process.
50) What happens if parent process terminate before its children? How this Problem is solved
To eliminate memory leaks?

In such a case, the system could be flooded with zombie processes whose Process descriptors would stay forever in RAM. This problem is solved by Forcing all orphan processes to become children of the init process. In this Way, the init process will destroy the zombies while checking for the Termination of one of its legitimate children through a wait( )-like system Call.

Entradas relacionadas: