Topics

  • Systemd targets
  • Journal logs
  • Process management (ps, nice, renice)
  • TuneD profiles

exercise_01.sh

executable safe: no requires: root
#!/bin/bash
# @type: executable
# @requires: root
# @safe: no
set -euo pipefail

# Exercise 1: Use systemctl to find the default systemd target on your system. 
# Use systemctl to temporarily switch your system to multi-user.target.
#
# Task: Display current default target and switch to multi-user target.

echo "Current default target:"
systemctl get-default

echo ""
echo "Switching to multi-user.target..."
sudo systemctl isolate multi-user.target

echo ""
echo "System is now in multi-user.target mode."

exercise_03.sh

executable safe: yes
#!/bin/bash
# @type: executable
# @requires: none
# @safe: yes
set -euo pipefail

# Exercise 3: Examine the output of journalctl -b to review the messages from the most recent system boot.
#
# Task: Display system journal entries from the current boot.

sudo journalctl -b

exercise_04.sh

executable safe: yes
#!/bin/bash
# @type: executable
# @requires: none
# @safe: yes
set -euo pipefail

# Exercise 4: Use the ps command to identify the top 3 processes consuming the most CPU and memory.
#
# Task: List processes sorted by CPU and memory usage.

echo "=== Top 3 CPU-consuming processes ==="
ps aux --sort=-%cpu | head -n 4

echo ""
echo "=== Top 3 Memory-consuming processes ==="
ps aux --sort=-%mem | head -n 4

exercise_05.sh

executable safe: yes
#!/bin/bash
# @type: executable
# @requires: none
# @safe: yes
set -euo pipefail

# Exercise 5: Start a new process with a non-default nice value using the nice command, 
# and then verify the change with ps.
#
# Task: Start a process with modified priority and verify it.

# Start sleep process with nice value of 10
nice -n 10 sleep 3600 &

PID=$!
echo "Started sleep process with PID: $PID and nice value 10"

# Verify the nice value
echo ""
echo "Process information:"
ps lax | grep sleep | grep -v grep

exercise_06.sh

executable safe: yes
#!/bin/bash
# @type: executable
# @requires: none
# @safe: yes
set -euo pipefail

# Exercise 6: Use renice to change the niceness of a running process, 
# and then confirm the change with ps.
#
# Task: Modify the priority of an already running process.

# First, we need a process to renice
# Start a sleep process in background
sleep 3600 &
PID=$!

echo "Started process with PID: $PID"
echo ""
echo "Original priority:"
ps lax | grep $PID | grep -v grep

# Change the nice value to 15
echo ""
echo "Changing nice value to 15..."
renice -n 15 $PID

# Verify the change
echo ""
echo "New priority:"
ps lax | grep $PID | grep -v grep

echo ""
echo "To kill this process, run: kill $PID"

exercise_07.sh

executable safe: no requires: root
#!/bin/bash
# @type: executable
# @requires: root
# @safe: no
set -euo pipefail

# Exercise 7: Use tuned-adm active to determine which performance profile is currently active on your system. 
# Switch the active TuneD profile to throughput-performance using the tuned-adm profile command.
#
# Task: Check current TuneD profile and switch to throughput-performance.

echo "Current active TuneD profile:"
tuned-adm active

echo ""
echo "Switching to throughput-performance profile..."
sudo tuned-adm profile throughput-performance

echo ""
echo "New active profile:"
tuned-adm active