Unix Processes Control Commands Like Ps and Top (Part C)

By Vijay

By Vijay

I'm Vijay, and I've been working on this blog for the past 20+ years! I’ve been in the IT industry for more than 20 years now. I completed my graduation in B.E. Computer Science from a reputed Pune university and then started my career in…

Learn about our editorial policies.
Updated March 9, 2024

Overview:

In this tutorial, we will cover the basics of Unix processes.

We will also cover the basic commands that are used to work with the processes such as ps and top

=> Click here for the Complete Unix Tutorial series

Unix Processes Control Commands

Unix Video #4

Unix Processes

A process is a context in which a program executes. Every time when a command or program is run, a new process is created. The process is active for as long as the program is in an active state.

For Example, if we are executing the cat command then a process named “cat” is generated.

Each time a new process is created, the Kernel assigns a unique identification number called the PID i.e. process identification number) which lies between 0 to 32,767. Other properties of processes include their PPID (Parent PID), TTY (the controlling terminal from where they were launched), UID (the user id that owns this process), and GID (the group that is associated with the process).

In Unix, the processes have a hierarchical relationship, where a parent process spawns the child processes. The ‘init’ process is the grandfathering process of all the other processes. In some cases, where the parent process is killed before the child process, the child is called an orphan process.

#1) Foreground Process

A process that is launched from a terminal and disallows further commands until it completes. In such a process, the stdin and stdout are attached to the terminal by default.

#2) Background Process

It is a process that was launched from a terminal but is run in the background, thus allowing further commands while it runs. In such a process, the stdin and stdout should typically be redirected so they don’t interfere with other foreground processes.

#3) Daemon Process

It is a process that is not associated with a terminal session. Such processes are usually launched for system services such as networking and printing.

In this tutorial, we will cover control commands, as well as the other commands that are used to manipulate the processes.

Control Commands

These commands are a two-key combination where a letter is pressed simultaneously with the ‘Ctrl’ key.

  • Control-C: This command terminates the currently running foreground process.
  • Control-D: This command terminates the currently running login or terminal session.
  • Control-Z: This command suspends the currently running foreground process to the background.

Other Commands:

Commandps - displays a snapshot of all current processes

Common Syntax

$ ps [options]
Example
$ ps -ef  
Show every process running, formatted as a table



Command

top - displays a live status of current processes

Common Syntax

$ top [options]
Example
$ top
Show a live view of all current processes


Command

bg - resume a background suspended a job

Common Syntax

$ bg [job_spec …]
Example$ xterm
Ctrl-Z
$ bg
Continue running a job that was previously suspended (using Ctrl-Z) in the background
Command

fg - bring a background job to the foreground

Common Syntax

$ fg [job_spec]
Example
$ xterm
Ctrl-Z
$ bg
$ fg

Bring a previous background job to the foreground
Command

clear – clear a terminal screen

Common Syntax

$ clear
Example
$ clear
Clear all prior text from the terminal screen
Command

history – print history of commands in the current session

Common Syntax

$ history [options]
Example$ history
Show list of previous commands that were entered

Take a look at our upcoming tutorial to know much more about Unix Commands.

=> Click here for the Complete Unix Tutorial series

PREV Tutorial | NEXT Tutorial

Was this helpful?

Thanks for your feedback!

Leave a Comment