Multitasking in Linux Terminal

Mohammed Faizan
2 min readMar 17, 2022

If you’re a sysadmin who spends a lot of time staring at that black and white screen having opened multiple sessions at a time and looking for ways to be more efficient then this article is for you. This is a simplified article based on how we can perform multiple tasks while logged in to a single session.

Suppose we have a command say “sleep 500”.

When we execute this command we need to wait for 500 plain seconds until we get back the prompt.

You can think of any other command which will basically take some time to execute.

Mostly what we do is we open up another session on the same server in order to carry out the rest of our work.

Solution:

Run the same command and just simply append “&” to the end of the command.

sleep 500 & 
[1] 10072

The output shows a new JOB_ID and a PROCESS_ID assigned to the background job.

You can look it up using jobs command and for that simply give

jobs -l
[1]+ 10072 Running sleep 500 &

The output displays 4 things: JOB_ID, PROCESS_ID, status and the CMD

How to stop the currently running job and continue it later?

We have 2 cases here:

  1. If the job is running on the foreground, just give Ctrl + Z and look it up usings jobs to verify.
  2. If the job is running on the background, you can either bring it to foreground using fg %JOB_ID and give Ctrl + Z
fg %1
sleep 500
^Z
[1]+ Stopped sleep 500

(OR)

Use kill command:

kill -STOP %1

How to resume the stopped process?

Again we have 2 cases here:

  1. If we want to resume it on the foreground,
fg %1
sleep 500

2. If we want to resume it on the background:

bg %1

OR

Use kill command:

kill -CONT %1

If you find this article helpful, please react to it positively and support me in my new job pursuit(link below) for maximum outreach.

https://www.linkedin.com/posts/mohammed-faizan-a2359315b_devops-awscloud-jenkins-activity-6899764199636000768-zes7

--

--