This Bash script is designed to monitor system resources, manage processes interactively, and provide real-time monitoring capabilities. It includes functions for logging activities, managing processes, displaying system statistics, and performing operations such as process termination and searching/filtering processes. The script utilizes configurations specified in Task_B_Options.conf
for thresholds and intervals.
- Monitors system resources (CPU and memory usage).
- Loads configurations from
Task_B_Options.conf
for thresholds and intervals. - Includes functions from
Functions_Task_B.sh
for logging activities, managing processes, and interacting with the user. - Provides an interactive menu for operations including listing processes, displaying process information, terminating processes, viewing system statistics, real-time monitoring, and searching/filtering processes.
- log_activity: Logs activities with timestamps to
Task_B.log
. - list_processes: Lists running processes sorted by CPU and memory usage.
- process_info: Provides detailed information about a specified process.
- kill_process: Terminates a specified process by its PID.
- process_statistics: Displays overall system process statistics including total processes, CPU load, and memory usage.
- real_time_monitoring: Provides real-time monitoring of running processes.
- search_processes: Allows searching and filtering of processes based on user-defined criteria.
- check_alerts: Monitors processes for high CPU and memory usage alerts, printing and logging detected alerts.
- cleanup: Terminates background processes and exits the script cleanly.
- interactive_mode: Provides an interactive menu for the user to select and execute various operations related to process management and system monitoring.
- Ensure Bash is installed on your system.
- Create and configure
Task_B_Options.conf
for custom settings such as thresholds and intervals. - Place
Functions_Task_B.sh
in the same directory asTask_B.sh
to ensure all functions are accessible.
-
Clone the repository to your local machine:
git clone <https://github.com/OmarElmelegy/Process_Monitor.git> cd <repository-directory>
-
Make the script executable:
chmod +x Task_B.sh
-
Run the script:
./Task_B.sh
-
Follow the interactive menu to perform operations related to process management and system monitoring.
./Task_B.sh
This command starts the interactive menu for the System Monitoring and Process Management script, allowing you to monitor and manage system processes interactively.
Edit Task_B_Options.conf
to customize thresholds and intervals:
# Example Task_B_Options.conf
UPDATE_INTERVAL=15
CPU_THRESHOLD=85
MEMORY_THRESHOLD=90
ALERTS_INTERVAL=2
The script traps exit signals (SIGINT
and SIGTERM
) to ensure proper cleanup of background processes:
# Trap [ctrl+c] or general termination of the script to trigger cleanup
trap cleanup SIGINT SIGTERM
# Cleanup function to terminate background processes
cleanup() {
if [[ $ALERTS_PID -ne 0 ]]; then
kill $ALERTS_PID
fi
exit 0
}
- If
Task_B_Options.conf
is missing or incorrectly configured, default settings will be used. - Ensure
Functions_Task_B.sh
is present in the same directory asTask_B.sh
to avoid errors related to missing functions.
- The script provides comprehensive functionalities for managing processes and monitoring system resources interactively.
- Properly terminate the script using the interactive menu option to ensure cleanup of background processes (
cleanup
function).