0% found this document useful (0 votes)
10 views11 pages

Process Commands

Uploaded by

Abhishek Bhalla
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views11 pages

Process Commands

Uploaded by

Abhishek Bhalla
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

PROCESS COMMANDS

1. ps
 This command stands for ‘Process Status’. It is similar to the
“Task Manager” that pop-ups in a Windows Machine when we
use Cntrl+Alt+Del.
 To check all the processes running under a user, use the
command –
ps ux
 To check the process status of a single process, use the
syntax –
ps PID

2. Top
 This utility tells the user about all the running processes on the
Linux machine.

 Press ‘q’ on the keyboard to move out of the process display.


3. pstree
 Pstree command in Linux that shows the running processes as a
tree which is a more convenient way to display the processes
hierarchy and makes the output more visually appealing. The root
of the tree is either init or the process with the given pid.
 To display process tree
pstree

4. nice
 Linux can run a lot of processes at a time, which can slow down
the speed of some high priority processes and result in poor
performance.
 To avoid this, you can tell your machine to prioritize processes
as per your requirements.
 This priority is called Niceness in Linux, and it has a value
between -20 to 19.
 The lower the Niceness index, the higher would be a priority
given to that task.
 The default value of all the processes is 0.
 To start a process with a niceness value other than the default
value use the following syntax
nice -n 'Nice value' process name

 In Linux, the nice & renice commands are used to change the
priority of a process, which, in effect, determines the urgency
with which it is executed in the system.

 The nice command configures the priority of a Linux process


before it is started. Once started, you cannot change the priority
using the nice command. This is where the renice command
comes in. The renice command sets the priority of an already
running process.

Priority Values in Linux


 In Linux systems, there are a total of 140 priorities with a nice
value that ranges from -20 to +19 where +19 represents the
lowest priority and -20 the highest priority. As you have noted,
this is an inverse proportionality relationship between the nice
value and the priority value.

 By default, any Linux process created by a user has a nice


value of 0.

 How to Check the Nice Value of Running Processes?


 There are a couple of ways of checking the nice value of
running processes. You can use the ps command with the -
l option, as follows:
$ ps-l

 The niceness value is denoted by the NI column header.


The PRI column header denotes the actual priority of the
process.
 Additionally, you can invoke the top command to check the
nice value of processes.
$ top

 The default niceness value for processes started by a regular


user is 0. In fact, you can easily verify the nice value for your
terminal or shell by executing nice command without any
arguments.

$ nice

How Set the Nice Value of a Process?


 The syntax of using the nice command is as follows:
$ nice -nice_value command-arguments
For example, to set a nice value of 5 to a command, run the
command below.

Here, we are downloading the WordPress installation file using wget


command with a nice value set to 5.

$ nice -5 wget https://wordpress.org/latest.zip

 To set a negative value to a command, use a double hyphen, as


shown. Be advised that you should run the command as root or sudo
user as you execute this.
$ sudo nice --5 wget https://wordpress.org/latest.zip

How to Change the Nice Value Using Renice?


The renice command changes the priority of a process that is already
running in the Linux system. To do so, use the syntax:

$ sudo renice –n nice_value -p pid_of_the_process

From the output, the nice value is 0. We are going to set it to 5, as shown
below. Note 8721 is the PID of the gnome-terminal process

$ sudo renice –n 5 -p 8721


SYSTEM CALLS IN LINUX

A system call is a procedure that provides the interface between a


process and the operating system. It is the way by which a computer
program requests a service from the kernel of the operating system.
Different operating systems execute different system calls.
In Linux, making a system call involves transferring control from
unprivileged user mode to privileged kernel mode; the details of this
transfer vary from architecture to architecture. The libraries take care of
collecting the system-call arguments and, if necessary, arranging those
arguments in the special form necessary to make the system call.
When running a computer, you interact with various programs that require
system resources like network, filesystem, memory, and CPU. And here's
where the concept of system calls kicks in! When a program requires a
system resource, it sends a request for that resource to the kernel by
making a system call.
The system calls are divided into five categories:

1. Process management system calls


2. File management system calls
3. Device management system calls
4. Network management system calls
5. System information system calls
PROCESS MANAGEMENT SYSTEM CALLS
These system calls are used to manage processes, such as starting new
ones, stopping existing ones, and waiting for them to finish. Fork(),
exec(), wait(), and exit() are all examples of process management
system calls ().
 fork(): As the name suggests, this creates a child process from the parent
process which results in the exact same process except for some values like
PID and parent PID.
 exec(): This system call replaces the current process image with the new
image and it is used when you want to run a different program from the
current process.
 wait(): This system call waits to will the child process gets terminated and
then gives some information about the child process. The prime example of
this would be the exit status.
 exit(): This system call terminates the current process and returns the
resources acquired by that process (which was terminated recently) to the
system.

FILE MANAGEMENT SYSTEM CALLS


These calls to the system are used to open, read, write, and close
documents, as well as to create, rename, and delete them.
 open(): As the name suggests, it is used to open the file.
 read(): This system call can be used to read data from a wide range of
data types including regular files, and special files like pipes and sockets,
and it can also read from device files like /dev directory. We cannot edit
the files with this system call. Multiple processes can execute the read()
system call on the same file simultaneously
 write(): It is used to modify files, generate log files, reports, etc. Multiple
processes cannot execute the write() system call on the same file
simultaneously
 close(): This will close the file and save the changes to the disk(if any).
DEVICE MANAGEMENT SYSTEM CALLS

The device management system calls are used to manage devices that are
connected to your system. In simple terms, the device management system
calls provides a way to read/write data, and control and configure those
devices.

Here are some common device management system calls:

ioctl(): It is referred to as Input and Output Control. It is used to send


control commands to the connected devices.

mmap(): It is used to map the partition of a file into the memory of the own
process. This results in direct access to the memory-mapped data as if it
was a part of the process's own memory.

For example, let's say you want to process a large file in a program so
rather than loading a whole file, you can map a portion of a file, use it and
then unmap it.

OR we can say ,

This function call is used to map or unmap files or devices into memory. The
mmap() system call is responsible for mapping the content of the file to the
virtual memory space of the process.
SYSTEM INFORMATION SYSTEM CALL
The system information system calls are used to get various kinds of
information such as system resources, system time, system configuration,
etc.

Here are some of the most commonly used system information calls:

 getpid(): Gets the PID (process ID) of the current process.


 getppid(): Gets the parent PID of the current process.
 getuid(): It will get the UID (used ID) of the current process.
 getgid(): It will get the GID (group ID) of the current process.
 uname(): This system call gets the information about the system name,
version, release info, and other system-related info.
 sysinfo(): It gets general information about the system which includes
free memory, total memory, number of current processes, etc.
 time(): It gets the current system time in seconds

NETWORK SYSTEM CALLS


The network system calls are used to manage networks, send/receive data,
resolve network addresses, etc.

And here are some of the popular network system calls:

 socket(): This system call is used to create sockets which are endpoints for
communication.
 bind(): It is used to bind a socket to the specific address and port on the
local network.
 listen(): It is used to mark the socket as a passive listener so it can accept
incoming requests from the other hosts.
 accept(): This system call is used to accept the new incoming connection
request.
 connect(): It establishes the connection to the external network endpoint.
 send(): As the name suggests, it is used to send data over the socket.
 recv(): It is used to receive data over the socket.

You might also like