Commands and Process
Commands and Process
• External Commands:
– Commands which aren’t built into the shell.
– When an external command has to be executed, the shell looks
for its path given in the PATH variable, and also a new process
has to be spawned and the command gets executed.
– They are usually located in /bin or /usr/bin.
– For example, when you execute the “cat” command, which
usually is at /usr/bin, the executable /usr/bin/cat gets executed.
– Examples: ls, cat etc.
The “type” command
• Example:
$ man 2 intro
• In this example, the manual pages of
command ‘intro‘ are returned which lies in the
section 2.
-f option: One may not be able to remember the sections
in which a command is present. So this option gives the
section in which the given command is present.
Syntax:
$ man -f [COMMAND NAME]
Example:
$ man -f ls
Output: In this example, the command ‘ls‘ is
returned with its section number.
• -a option: This option helps us to display all the
available intro manual pages in succession.
• Syntax:
$ man -a [COMMAND NAME]
• Example
$ man -a intro
• Output
• In this example you can move through the manual
pages(sections) i.e either reading(by pressing Enter) or
skipping(by pressing ctrl+D) or exiting(by pressing
ctrl+C).
• -k option: This option searches the given command
as a regular expression in all the manuals and it
returns the manual pages with the section number in
which it is found.
$ man -k [COMMAND NAME]
• Example:
$ man -k cd
• Output
• The command ‘cd‘ is searched in all the manual
pages by considering it as a regular expression.
• -w option: This option returns the location in which
the manual page of a given command is present.
• $ man –w [ COMMAND NAME]
• Example
• $man -w ls
• Output
• The location of command ‘ls‘ is returned.
• -I option: It considers the command as case
sensitive.
• $ man –I [ COMMAND NAME]
• Example
• $man -I printf
• Output:
• The command ‘printf‘ is taken as case-
sensitive i.e ‘printf‘ returns the manual pages
but ‘Printf‘ gives error.
Operating system Processes
• getpid()getprocessid
• getppid() getparentprocessid
Parent Process
Simple process selection : Shows the processes for the current shell –
[root@rhel7 ~]# ps
• PID TTY TIME CMD
• 12330 pts/0 00:00:00 bash
• 21621 pts/0 00:00:00 ps
• Result contains four columns of information.
Where,
PID – the unique process ID
TTY – terminal type that the user is logged into
TIME – amount of CPU in minutes and seconds that the process has been
running
CMD – name of the command that launched the process.
• View Processes : View all the running processes use
either of the following option with ps –
• [root@rhel7 ~]# ps -A
• [root@rhel7 ~]# ps -e
• Syntax:
• at [OPTION...] runtime
• Options:
-V: It is used to display the number to standard errors and
exit successfully.
-q: It is used to specify the queue. The queue designation
consists of a letter. It ranges from a to z or A to Z. The
queue is the default queue, and the b queue is used for
the batch. The queues with the higher letters run with
increased priority. The queue '=' is a special queue; it is
reserved for the currently running jobs.
-m: It is used to send mail to the user when the job is
successfully executed. It will work if there is no output.
-M: It is used to never send mail to the user.
-f: It is used to read the job from the file rather than standard
output.
-t: It is used to specify the time to run a job; it will be in the
format [[CC]YY]MMDDhhmm[.ss].
-l: The -l option is an alias for the atq command.
-r: The -r option is an alias for the atrm command.
-d: The -d option is an alias for the atrm command.
-b: The -b option is an alias for the batch command.
-v: The -v option is used to display the time of the job before
execution.
The nice command
• nice command in Linux helps in execution of a
program/process with modified scheduling priority.
• It launches a process with a user-defined scheduling
priority. In this, if we give a process a higher priority, then
Kernel will allocate more CPU time to that process.
• Run COMMAND with an adjusted niceness, which affects
process scheduling. With no COMMAND, print the
current niceness. Nicenesses range from -20 (most
favorable scheduling) to 19 (least favorable).
• SYNOPSIS
• nice [OPTION] [COMMAND [ARG]...]
Tag Description
--help
display this help and exit
--version output version information and exit
• 1. To check the nice value(priority) of a process.
– ps -el | grep terminal
• 2. To set the priority of a process
– nice -10 gnome-terminal
• 3. To set the negative priority for a process
– nice --10 gnome-terminal
• 4. changing priority of the running process.
– sudo renice -n 15 -p 77982
Background Processes
• SYNOPSIS
• bg [PID...]
• OPTIONS
Tag Description
[PID] If PID is specified, the jobs with the specified group ids
are put in the background.
• EXAMPLES
• To put the job with job id 0 in the background.
• bg %0
• fg command
• The fg command is like bg command except
that instead of sending a command in the
background, it runs them in the foreground
and occupies the current terminal and waits
for the process to exit.
• # jobs
• [1]- Stopped makewhatis
• [2]+ Stopped vi
• Without any argument, fg will run the current job in
the foreground (vi in this case).
• # fg Vi
• As the command is running in the foreground, we
don't get back the terminal until command exits. So,
jobs command will now show only one job as vi will
exit by now.
• # jobs
• [1]+ Stopped makewhatis
• # fg %1
• makewhatis
• # jobs
The kill command
• kill command in Linux (located in /bin/kill), is a built-
in command which is used to terminate processes
manually.
• kill command sends a signal to a process which
terminates the process.
• If the user doesn’t specify any signal which is to be
sent along with kill command then
default TERM signal is sent that terminates the
process.
• SYNOPSIS
• kill [ -s signal | -p ] [ -a ] [ -- ] pid ...
kill -l [ signal ]
• 1. kill -l :To display all the available signals you can use below
command option:
• Syntax:
• $kill –l
• 2. kill pid : To show how to use a PID with
the kill command.
• Syntax:
• $kill pid
• 3. kill -s : To show how to send signal to processes.
• Syntax:
• kill {-signal | -s signal} pid
• 4. kill -L :This command is used to list available signals
in a table format.
• Syntax:
• kill {-l | --list[=signal] | -L | --table}
Example:
• Kill –l
• Kill –L
• Kill –list[=signal]
• Kill -- table
The find command
• The find command in UNIX is a command line
utility for walking a file hierarchy.
• It can be used to find files and directories and
perform subsequent operations on them.
• It supports searching by file, folder, name,
creation date, modification date, owner and
permissions.
• By using the ‘-exec’ other UNIX commands can be
executed on files or folders found.
• Syntax :
• $ find [where to start searching from] [expression determines what
to find] [-options] [what to find]