Intermediate Bash - Processes and Jobs

Question Click to View Answer

Display all the processes of a given shell.

ps

ps stands for 'process status'

Display all processes running on your machine, including processes without a controlling terminal.

ps -x

Most processes on a Unix machine are run without a controlling terminal.

Show every process on the computer, updated every couple of seconds.

top

The top command shows how much CPU each processes is using.

Write a command that suspends execution for 3 seconds.

sleep 3

Run the following command in the background: sleep 1000

sleep 1000 &

When commands are followed by &, they are run in the background.

Run the sleep 500 command in the background and then show all the processes that are running in the background.

sleep 500 & jobs

Run the sleep 300 command in the background and then stop the process.

# start the process
sleep 300 &

# find the PID (process ID)
ps

# PID is 17114 on my machine
kill 17114

# verify the process is terminated
jobs

The kill command is use to send signals (like interrupt, quit, abort, or kill) to processes. kill sends a software termination signal by default.

Suppose a process has a PID of 10100 and does not respond to the kill 10100 command. How can this command be terminated?

kill -9 10100

kill -9 sends a KILL signal, which immediately terminates the process. kill -9 does not do any cleanup, so it's best to avoid, but is sometimes necessary when processes don't respond to kill (which is the same as kill -15). Type $ man kill to learn more about the kill command.

Run sleep 2200 in the foreground and then send a SIGSTOP signal to the process.

sleep 2200
# Press Control + z

Run sleep 3333 in the foreground and then send a SIGSTOP signal to the process. Start the process back up in the background.

sleep 3333
# Press Control + z to send SIGSTOP signal to process
# Find job number
jobs
# job number is 1 on my machine
# Restart job in background
bg %1

Run sleep 999 in the foreground and then send a SIGINT signal to the process. Then start the process back up in the foreground.

sleep 999
# Press Control + c to send a SIGINT signal to the process

Once a SIGINT signal is sent to a process, the process cannot be restarted.