5.understanding Processes
5.understanding Processes
Student Handout
Student Handout: Understanding Processes
in Linux
Introduction to Processes
A process is a running instance of a program in Linux.
Each process has a unique Process ID (PID).
Background Processes
Definition: Runs in the background, allowing terminal use for other tasks.
Example 1: sleep 60 & runs the sleep command for 60 seconds in the background.
Example 2: wget http://example.com/file.zip & downloads a file without blocking the
terminal.
Example 3: find / -name "*.txt" & searches for text files across the system in the
background.
Managing Processes
Bringing a Foreground Process to the Background
1. Pause the process: Use Ctrl + Z .
2. Send to background: Use bg command.
Example:
$ cat largefile.txt
# Press Ctrl + Z
$ bg
$ fg
Killing a Process
Command: kill <PID> terminates a process.
Force Kill: kill -9 <PID> forcefully kills a process.
Example 1: kill 1234 terminates the process with PID 1234.
Example 2: kill -9 5678 forcefully kills the process with PID 5678.
Example 3: pkill firefox kills all processes related to Firefox.
Example Script:
#!/bin/bash
echo "Hello, World!"
sleep 5
echo "This is a simple shell script."
#!/bin/bash
ls -l
#!/bin/bash
date
#!/bin/bash
mkdir new_directory
Conclusion
Processes: Running instances of programs with unique PIDs.
Foreground vs. Background: Foreground takes terminal control; background allows
multitasking.
Process Management: Use ps , bg , fg , and kill to manage processes.
Shell Scripting: Automate tasks by writing commands in a script.
Feel free to ask questions if you need further clarification on any topic!