Unix uses processes to run programs and operating system functions. There are two types of processes - system processes which execute OS code and user processes which execute user programs. Processes can be in different states like running, ready, blocked etc. The kernel manages processes using data structures like process table entry and user area. Important process management operations include forking to create new processes, wait/exit for process termination, and signals for inter-process communication.
In this presentation, I am explaining about Threads, types of threads, its advantages and disadvantages, difference between Process and Threads, multithreading and its type.
"Like the ppt if you liked the ppt"
LinkedIn - https://in.linkedin.com/in/prakharmaurya
In this presentation, I am explaining about Threads, types of threads, its advantages and disadvantages, difference between Process and Threads, multithreading and its type.
"Like the ppt if you liked the ppt"
LinkedIn - https://in.linkedin.com/in/prakharmaurya
Operating System ,UNIX & LINUX base System Calls
1) Process Creation
2) Executing a Command
3) Wait command
4) Sleep Command
5) Sleep Command using getpid
6) Signal Handling
With C-Programming & BASH Programming
INTRODUCTIONTO OPERATING SYSTEM
What is an Operating System?
Mainframe Systems
Desktop Systems
Multiprocessor Systems
Distributed Systems
Clustered System
Real -Time Systems
Handheld Systems
Computing Environments
Quontra Solutions offers Job oriented Linux online training with updated technologies. For more info about our Linux online training contact us directly. We are providing Linux online training to all students throughout worldwide by real time faculties. Our Linux training strengthens your skills and knowledge which will helps you to gain a competitive advantage in starting your career. Outclasses will help you to gain knowledge on real time scenario. It will be most use full to boost up your career.
Our training sessions are designed in such a way that all the students can be convenient with the training schedules and course timings.
Along with Training, we also conduct several mock interviews along with Job Placement Assistance. Attend Free Demo before joining the class.
Our Features:
• Real world projects to get practical based experience
• Online tests to explore the resource learning
• Experienced certified trainers as instructors
• One to one personalized training with desktop access
• Case studies and state of art library to access study material
• Resume build assistance to win in interviews
Contact us:
Simson Andrew
Email: info@quontrasolutions.com
web: www.quontrasolutions.com
Virtual Memory
• Copy-on-Write
• Page Replacement
• Allocation of Frames
• Thrashing
• Operating-System Examples
Background
Page Table When Some PagesAre Not in Main Memory
Steps in Handling a Page Fault
Process management in operating system | process states | PCB | FORK() | Zomb...Shivam Mitra
This is the second part of the operating system interview series.
In this session, we will look at the following:
1. Program vs process
2. Process states
3. Process control block
4. Process lifecycle using fork(), exec(), exit() and wait()
5. Zombie and orphan process
Unix Process Management
Process management is an integral part of any modern day operating system (OS). The OS must allocate resources to processes, enable processes to share and exchange information, protect the resources of each process from other processes and enable synchronisation among processes
Operating System ,UNIX & LINUX base System Calls
1) Process Creation
2) Executing a Command
3) Wait command
4) Sleep Command
5) Sleep Command using getpid
6) Signal Handling
With C-Programming & BASH Programming
INTRODUCTIONTO OPERATING SYSTEM
What is an Operating System?
Mainframe Systems
Desktop Systems
Multiprocessor Systems
Distributed Systems
Clustered System
Real -Time Systems
Handheld Systems
Computing Environments
Quontra Solutions offers Job oriented Linux online training with updated technologies. For more info about our Linux online training contact us directly. We are providing Linux online training to all students throughout worldwide by real time faculties. Our Linux training strengthens your skills and knowledge which will helps you to gain a competitive advantage in starting your career. Outclasses will help you to gain knowledge on real time scenario. It will be most use full to boost up your career.
Our training sessions are designed in such a way that all the students can be convenient with the training schedules and course timings.
Along with Training, we also conduct several mock interviews along with Job Placement Assistance. Attend Free Demo before joining the class.
Our Features:
• Real world projects to get practical based experience
• Online tests to explore the resource learning
• Experienced certified trainers as instructors
• One to one personalized training with desktop access
• Case studies and state of art library to access study material
• Resume build assistance to win in interviews
Contact us:
Simson Andrew
Email: info@quontrasolutions.com
web: www.quontrasolutions.com
Virtual Memory
• Copy-on-Write
• Page Replacement
• Allocation of Frames
• Thrashing
• Operating-System Examples
Background
Page Table When Some PagesAre Not in Main Memory
Steps in Handling a Page Fault
Process management in operating system | process states | PCB | FORK() | Zomb...Shivam Mitra
This is the second part of the operating system interview series.
In this session, we will look at the following:
1. Program vs process
2. Process states
3. Process control block
4. Process lifecycle using fork(), exec(), exit() and wait()
5. Zombie and orphan process
Unix Process Management
Process management is an integral part of any modern day operating system (OS). The OS must allocate resources to processes, enable processes to share and exchange information, protect the resources of each process from other processes and enable synchronisation among processes
OS | Functions of OS | Operations of OS | Operations of a process | Scheduling algorithms | FCFS scheduling | SJF scheduling | RR scheduling | Paging | File system implementation | Cryptography as a security tool
What is program and process .
Program execution flow .
Example of process generation .
Description of process .
Types of process .
Ways of run process .
How process is generated using fork() and execution .
Process life cycle .
Process tree .
Process states .
Load Averages .
For monitoring and managing linux process tools .
Signals are software interrupts that give us a way to handle asynchronous events.Stuck with your System Programming Assignment. Get 24/7 help from tutors with Phd in the subject. Email us at support@helpwithassignment.com
Reach us at http://www.HelpWithAssignment.com
The second part of Linux Internals covers system calls, process subsystem and inter process communication mechanisms. Understanding these services provided by Linux are essential for embedded systems engineer.
Week 11
Linux Internals
Processes, scheduling
Lecture organization
Kernel Structure
Process structure
Process creation
Signals
Process management, scheduling
Linux for embedded systems
References
Linux Internals (to the power of -1)
Simone Demblon, Sebastian Spitzner
http://www.tutorialized.com/view/tutorial/Linux-kernel-internals-from-Process-Birth-to-Death/40955
Linux Knowledge Base and Tutorial
http://linux-tutorial.info/modules.php?name=MContent&pageid=224
Inside the Linux scheduler IBM Developer Works
http://www.ibm.com/developerworks/linux/library/l-scheduler/
The Linux Kernel
A Unix kernel fulfills 4 main management tasks:
• Memory management
• Process management
• File system management
• IO management
For our study of real time implications, we will examine Process management
A Rather brief look at the kernel
Part 1
Process structure
Process data structure
A process is represented by a rather large structure called task_struct.
It contains all of the necessary data to represent the process, along with data for accounting and to maintain relationships with other processes (parents and children).
The actual structure of the task_struct is many pages long
A short sample of task_struct is shown in the next slide
Task_struct
Pointers to open files
Memory map
Signals: received, masked
Register contents
Everything defining the state of the computation
Task_struct detail
The sample contains the state of execution, a stack, a set of flags, the parent process, the thread of execution (of which there can be many), and open files.
The state variable: the state of the task.
Typical states:
the process is running
In a run queue about to be running (TASK_RUNNING),
sleeping (TASK_INTERRUPTIBLE),
sleeping but unable to be woken up (TASK_UNINTERRUPTIBLE),
stopped (TASK_STOPPED), or a few others.
Flags: the process is being created (PF_STARTING) or exiting (PF_EXITING), or currently allocating memory (PF_MEMALLOC).
The comm (command) field: the name of the executable
Priority: (called static_prio). The actual priority is determined dynamically based on loading and other factors.
More Task_struct
The tasks field is a linked-list
mm and active_mm fields The process's address space. mm represents the process's memory descriptors, while the active_mm is the previous process's memory descriptors
The thread_struct identifies the stored state of the process: The CPU state (hardware registers, program counter, etc.).
Part 2
Process creation
System call functions
user-space tasks and kernel tasks, rely on a function called do_fork to create the new process.
In the case of creating a kernel thread, the kernel calls a function called kernel_thread
In user-space, a program calls fork, which results in a system call to the kernel function called sys_fork
The function relationships are shown graphically in the next slide.
Function hierarchy for process creation
do_fork
The do_fork f.
2. Unix Process Management
♦ Operating system functions executes within
user process.
♦ 2 modes of execution
– User mode and Kernel mode
♦ 2 types of processes are available
– System processes(Execute OS code)
– User processes( Execute user program code).
♦ System call is used to transfer from user
mode to system mode.
1/30/2004 Operating Systems 2
5. ♦ Preemption can only occur when the
process is about to move from Kernel mode
to User mode.
♦ While the process is running in Kernel
mode it may not be preempted. This make
UNIX not suitable for real time processing.
♦ Process 0 is a special process that is created
when the system boots. Process 1 (init
process) is the child of Process 0. All the
other processes in UNIX has Process 1 as
ancestor. All new processes are created
under Process 1 (init process).
1/30/2004 Operating Systems 5
6. Process Description
♦ Elements of process image -- divided into 3
– User level context
• Process text, Process data, User stack and Shared memory.
– Register context
• Program counter, Process status registers, stack pointer,
general purpose registers…
– System level context
• Process table entry, User area, Per process region table, Kernel
stack
– When a process is not running the processor status
information is stored in register context area.
1/30/2004 Operating Systems 6
7. Unix Process Table Entry
♦ Process status
♦ Pointers – to user area & process memory area
(text, data, stack)
♦ Process size – enables OS to know how much
space to allocate
♦ User identifier
– Real user ID - ID of user who is responsible for the
process
– Effective user ID used by process to gain temporary
privilege, while the program is being executed as a part
of process.
– Process identifiers ID of the process
1/30/2004 Operating Systems 7
8. ♦ Event descriptor valid when a process is in
sleep state. When the event occurs, the process is
transferred to a ready to run state.
♦ Priority used for scheduling
♦ Signal enumerates signals send to process but
not yet handled.
♦ Timers Process execution time, kernel resource
utilization, and user set timer used to send alarm
signal to a process.
♦ P_link pointer to the next link in the ready
queue.
♦ Memory status indicates the process image is in
the main memory or swapped out.
1/30/2004 Operating Systems 8
9. UNIX User Area
♦ Process table pointer Indicates entry
corresponding to the user area.
♦ User identifiers Real & Effective user Ids, used
to determine user privileges.
♦ Timers Record time that the process spent
executing in user mode & kernel mode.
♦ Signal handling array For each type of signal
defined in the system, indicate how the process
will react to receipt of that signal.
♦ Control terminal Indicate login terminal for this
process, if exist.
♦ Error field Record errors encountered during
system call.
1/30/2004 Operating Systems 9
10. ♦ Return value Contain result of s/m call
♦ I/O parameters Describes amount of data
transfer, the address of the source data array in
user space, file offset for I/O.
♦ File parameters Current directory & current
root describe the file system environment of the
process.
♦ User file descriptor table Record the file the
process has open
♦ Limit fields Restrict the size of the process &
size of the file it can write.
♦ Permission mode field Mask mode settings on
files the process creates.
1/30/2004 Operating Systems 10
11. System level context
♦ 2 parts
– 1. Static (Process table entry, User area, Per process
region table).
– 2. Dynamic (Kernel stack)
– Process table entry contains process control information
that is accessible to the kernel to the kernel at all time.
So in VM systems all process table entries are
maintained in main memory.
– User area contains additional process control
information that is needed by the kernel when it
executes in context of a process. It is also used when
swapping process to and from the memory.
– Process reg. table is used by memory management s/m
– Kernel stack – used when the process is executing in
kernel mode and contain information that must be
saved and restored as procedure calls and interrupts
1/30/2004 occurs. Operating Systems 11
12. #include <stdio.h>
Fork program in C
#include <unistd.h>
int main(int argc, char *argv[])
{
int pid;
/* fork another process */
pid = fork();
if (pid < 0) { /* error occurred */
fprintf(stderr, "Fork Failed");
exit(-1);
}
else if (pid == 0) { /* child process */
execlp("/bin/ls","ls",NULL);
}
else { /* parent process */
/* parent will wait for the child to complete */
wait(NULL);
printf("Child Complete");
exit(0);
}
}
1/30/2004 Operating Systems 12
13. Fork() in UNIX
♦ Allocate slot in the process table for the new
process
♦ Assigns a unique process id to the new process
♦ Make a copy of the process image of the parent,
with the exception of shared memory
♦ It increases counters for any files owned by the
parent, to reflect that an additional process now
also owns these files.
♦ It assigns the child process to a ready to run state
♦ It returns the ID number of the child to the parent
process and a 0 value to the child process.
♦ These all works are done in Kernel of parent
process.
1/30/2004 Operating Systems 13
14. ♦ After completing those functions OS will do
the following operations as a part of
dispatcher routine
– Stay in the parent process. Control returns to
the user mode at the point of the fork call of the
parent.
– Transfer control to the child process. The child
process begins executing at the same point in
the code as the parent, namely at the return
from the fork call.
– Transfer control to another process. Both child
and parent are left in the ready to run state.
1/30/2004 Operating Systems 14
15. Types of processes in UNIX
♦ Mainly 3 types
– User process
– Daemon process
– Kernel process
– Daemon process
• Performs the function in a system wide basis. The function can
be of any auxiliary kind, but they are vital in controlling the
computational environment of the system.
• Example Print spooling, Network Management.
• Once created Daemon process can exist throughout the life
time of the Operating System.
1/30/2004 Operating Systems 15
16. Process Tree in a UNIX system
1/30/2004 Operating Systems 16
17. Termination of a process in UNIX
♦ Exit(status_code)
– Status_code indicate the termination status of the
process.
– Kernel does the following after receiving the exit call
• Close all open files of the process
• Releases the memory allotted to it
• Destroy the User area of the process
– It does not destroy the proc structure, this is retained till
the parent of Pi destroy it.
– The terminated process is dead but still exists. Hence it
is called ZOMBIE process.
– The exit call also sends signal to the parent of Pi which
may be ignored by the parent.
1/30/2004 Operating Systems 17
18. Wait statement in UNIX
– Pi can wait for the termination of a child
– Wait(address(xyz)); // xyz variable within the
address space of Pi.
– If process Pi has child processes & at least one of them
has already terminated, the wait call stores the
termination status of the terminated child process into
xyz and immediately return with the id of the
terminated child process. If more child processes exists
their termination status would be made available to Pi
only when it repeats the wait call.
– Process Pi is blocked if it has children but none of them
has terminated, it will be unblocked when one of the
child process terminates. The wait call returns a –1 if Pi
has no children.
1/30/2004 Operating Systems 18
19. Example for wait
Int main()
{
int I,saved_status;
for(I=0;I<3;I++)
{
if (fork()==0)
{
// Child Process
exit();
}
}
while(wait(&saved_status)!= -1); // Loop till all children
terminates
}
1/30/2004 Operating Systems 19
20. Interrupt handling in UNIX
♦ Will execute only one interrupt at a time ( to
avoid race condition).
♦ Each interrupt is assigned an interrupt
priority level. An interrupt priority level is
also assigned to CPU.
♦ When an interrupt at priority level ‘l’ arises,
it is handled only if l> CPU’s interrupt
priority else kept pending till CPU’s
interrupt priority level assumes a lower
value.
1/30/2004 Operating Systems 20
21. System calls in UNIX
– System calls accepts parameters relevant to its
functioning
– When a call occurs these parameters exists on the user
stack of the process which issues the system call.
– The call number is expected to be in register 0
– System call handler obtain this number to determine
which system functionality being invoked.
– From its internal table it knows the address of the
handler for that function.
– Parameters of the system call exists on the user stack of
the process making the call.
– Before passing control to the handler for a specific call
these parameters are copied from the user stack into
some standard places in the user area.
1/30/2004 Operating Systems 21
22. System calls in UNIX Cont…
– A signal can be send to a process/Group of
processes using kill(<pid>,<signum>) system
call. Where pid is the id of the process signal to
be sent.(sender must know receiver address &
receiver must be in the same process tree).
– Pid value 0 signal to be sent to all processes
in the same group as the sender process.
– Pid value –1 to reach processes outside the
process tree of the sender.
1/30/2004 Operating Systems 22
23. Signal handling in UNIX
♦ Oldfunction = signal(<signum>,<function>)
– Where signal is a function in C library which
makes a signal system call. Signum is an
integer & function is the function name.
– The function should be executed on occurrence
of signal <signum>.
– User can specify 0 or 1 instead of function.
Where 0 indicates the default action defined in
the Kernel is to be executed & 1 occurrence
of signal is to be ignored.
1/30/2004 Operating Systems 23
24. ♦ Whenever a signal is send to a process, the bit
corresponding to the signal is set to 1 in the proc
structure of the destination process. The kernel
now determines if the signal is being ignored by
the destination process. If not it will makes
provision to deliver the signal to the process. If the
signal is ignored it remains pending and is
delivered when the process is ready to accept it. In
UNIX signal remains pending if the process to
which it is intended is in block state. The signal
would be delivered when the process comes out of
the blocked state. Signals are delivered when
♦ A process returns from a system call, after a
process get unblocked, before a process gets
blocked.
1/30/2004 Operating Systems 24
25. Interesting signals in UNIX
♦ SIGCHLD Child process died or suspended
♦ SIGFPE Arithmetic fault
♦ SIGILL Illegal instruction
♦ SIGINT tty interrupt (Control C)
♦ SIGKILL Kill process
♦ SIGSEGV Segmentation fault
♦ SIGSYS Invalid System call
♦ SIGXCPU Exceeds CPU limit
♦ SIGXFSZ Exceeds file size limit
1/30/2004 Operating Systems 25