Professional Documents
Culture Documents
LP Unit-4
LP Unit-4
Unit-IV
COURSE OUTCOMES
1. Understand various Linux System utilities.
2. Demonstrate the shell scripts in shell Environment.
3. Understand the basic principles of file system architecture.
4. Apply the core concept of Process management and implement in the Linux Environment.
5. Compare various Inter-Process communication and Client-Server Application techniques In Linux environment
Process: Introduction to Process
• A Process is an instance of a running program.
• A process uses various system resources like memory
devices etc.
• Each Linux process has a parent and one or more
children.
• The init process is the first user process which is
created when the system boots for the first time
• It is the parent process for all the user processes.
• Each and every process has unique non-negative
identifier called the process ID.
Process: Introduction to Process
• A process is created by calling the fork() or vfork()
system call.
• A process may execute one or more programs.
• Life time of a process begins when it is created and ends
when the process terminates by calling exit system call
Process: Introduction to Process
A process is a program in execution.
Processes exist in main memory.
Process: Introduction to Process
Code Section: Sequence of Instructions
Every process apart from the PID also has a PUID and a PGID.
There are two types of PUID and PGID:
◦ This is normally the same as the real UID, except when the file that was executed to
create the process has its set-UID flag turned on ( via the chmod command or API).
◦ In the case, the process eUID will take on the UID of the file.
◦ This allows the process to access and create files with the same privileges as the
program file owner.
#include<unistd.h>
pid_t getpid (void) :- returns process ID of calling process
pid_t getppid (void) :- returns parent process ID of calling process
uid_t getuid (void) :-returns real user ID of calling process
uid_t geteuid (void) :- returns effective user ID of calling process
gid_t getgid (void) :- returns reak griyo ID if calling process
gid_t getegid (void) :- returns effective group ID of calling process
Process : Process 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, which is defined in <linux/sched.h>.
• The task structure contains all the information about a specific
process.
Process : Process Table
Process : Process Table
• The process control block (PCB) maintains information that the
operating system needs in order to manage a process.
• PCBs typically include information such as the process ID, the
current state of the process (e.g. running, ready, blocked, etc.),
• the number of the next program instruction to be executed, and the
starting address of the process in memory.
• The PCB also stores the contents of various processor registers
(the execution context),
• which are saved when a process leaves the running state and
which are restored to the processor when the process returns to
the running state.
Process :Viewing Processes
• The most common way to list processes currently running on your
system is to use the command ps
5.
Software conditions can generate signals (i.e. SIGURG, SIGPIPE,
SIGALRM, etc).
Signals : signals
Signal dispositions (i.e. Actions associated with signals):
If the signal causes a handler to be called, raise() will return only after
the signal handler has returned.
raise() returns 0 on success, and nonzero for failure.
Signals : alarm System Calls
alarm - set an alarm clock for delivery of a signal
#include <unistd.h>
unsigned int alarm(unsigned int seconds);
The alarm function sets an alarm clock to send a SIGALRM signal
after "seconds".
It is possible due to system overhead for the signal to be delivered
slightly off time.
There is only one of these alarm clocks per process. If we call alarm
more than once, we are resetting the alarm clock to a new value.
alarm(0) cancels any pending alarms
Returns: 0 or number of seconds since previously set alarm
Signals : Pause System Calls
pause - wait for signal
#include <unistd.h>
int pause(void);
pause() causes the calling process (or thread) to sleep until a signal is
delivered that either terminates the process or causes the invocation
of a signal-catching function.
pause() returns only when a signal was caught and the signal-catching
function returned.
In this case, pause() returns -1, and errno is set to EINTR.
ERRORS
EINTR a signal was caught and the signal-catching function returned.
Signals : abort System Calls
abort - cause abnormal process termination
#include <stdlib.h>
void abort(void);
The abort() first unblocks the SIGABRT signal, and then raises that
signal for the calling process.
sleep() causes the calling thread to sleep either until the number of
real-time seconds specified in seconds have elapsed or until a signal
arrives which is not ignored.
Zero if the requested time has elapsed, or the number of seconds left to
sleep, if the call was interrupted by a signal handler.
Signals : Signal Set
Signal Sets
All of the signal blocking functions use a data structure called
a signal set to specify what signals are affected.
Thus, every activity involves two stages: creating the signal set, and
then passing it as an argument to a library function.
These facilities are declared in the header file signal.h.
Data Type: sigset_t