AWS re/Start Lab · Linux

Managing Processes

Monitor system performance, list running processes, and automate repetitive tasks by configuring a scheduled cron job.

Lab Summary

Connected via PuTTY (as described in Lab 225). Generated a filtered log file of system processes using ps and grep. Examined the real-time resource utilization via top. Established an automated auditing task with crontab.

Process Listing

Used ps -aux filtered by grep -v root to log non-root processes into a CSV file via tee.

Performance Monitoring

Executed top to observe real-time CPU, memory, and thread metrics, identifying the number of active, sleeping, and zombie tasks.

Cron Jobs

Configured a repetitive task in the cron tab to run a file filtering script automatically.

Step-by-Step Walkthrough

Detailed record of each task performed during the lab.

01

SSH Connection

  • Connected to the EC2 instance via PuTTY following the process described in Lab 225.
02

Create List of Processes

  • Ensured the working directory was /home/ec2-user/companyA.
  • Piped the output of all system processes directly into a log file, filtering out the root user: sudo ps -aux | grep -v root | sudo tee SharedFolders/processes.csv.
  • Verified the file was properly generated using: cat SharedFolders/processes.csv.
The grep -v argument implements an inverse match. By searching for root with this flag enabled, it removes every row containing that word.
03

List Processes via top

  • Ran the top command to view dynamic, real-time metrics of the system.
  • Analyzed the Tasks output on the second line. Noted that out of 93 total tasks, there was 1 running, 48 sleeping, 0 stopped, and 0 zombie tasks.
  • Gained insights regarding CPU, physical memory (RAM), and swap space utilization.
  • Pressed q to exit the dynamic monitoring interface.
  • Ran top -hv to find usage and version information.
04

Establish a Cron Job

  • Used sudo crontab -e to securely edit the scheduled tasks file using the default text editor (usually Vim).
  • Configured the SHELL, PATH, and MAILTO environment variables.
  • Added a scheduled command at the bottom: 0 * * * * ls -la $(find .) | sed -e 's/..csv/#####.csv/g' > /home/ec2-user/companyA/SharedFolders/filteredAudit.csv.
  • Saved and closed the file utilizing :wq.
  • Validated the schedule creation with sudo crontab -l, which lists the installed cron jobs.
The six characters 0 * * * * determine when the job runs: minute, hour, day of month, month, and day of week. This syntax schedules the script to run exactly at the top of every hour.

Command Reference

Commands utilized in this lab.

cmd

ps

Reports a snapshot of the current processes running locally.

  • -aux : Lists all processes owned by all users (-a), user-oriented format (-u), including those without a terminal (-x)
cmd

grep

Searches input text strictly matching a predefined pattern.

  • -v : Inverts the match, returning everything except queries aligning with the pattern
cmd

top

Provides a dynamic real-time view of running processes prioritized by hardware resource consumption.

  • q : Terminates the top view
cmd

crontab

A software utility driving task scheduling and background automation via a daemon.

  • -e : Opens the crontab script file inside an editor for modifications
  • -l : Lists the currently active, configured jobs

Key Learnings

What Was Learned

Differences between the static snapshot output from ps and the real-time continuous feed given by top.
Excluding particular rows within terminal data returns using the -v flag on the grep command.
Understanding the anatomy of top screen outputs evaluating states like zombie or sleeping.
Syntax formats defining frequency and scheduling instructions on a cron utility.

Technical Conclusion

Detecting resource exhaustion prevents critical server outages. Leveraging top allows rapid diagnoses of memory and CPU constraints by exposing the exact software threads causing bottlenecks.

Automating system hygiene elements via cron is indispensable. Without scheduled routines, administrators must manually audit access files resulting in human error rates and inefficiencies.