Create monitor and terminate process

From Mintarc Forge

& - Run a command in the background

The & symbol is used to run a command or script in the background, allowing you to continue using the terminal.

Examples:

  • long_running_script.sh &: Run the script in the background
  • sleep 60 &: Run the sleep command for 60 seconds in the background
  • nohup command &: Run a command in the background, immune to hangups

bg - Resume suspended jobs in the background

bg resumes execution of a suspended job in the background.

Examples:

  • bg %1: Resume the first suspended job in the background
  • bg %vim: Resume the suspended vim job in the background
  • bg: Resume the most recently suspended job in the background

fg - Bring background jobs to the foreground

fg brings a background job into the foreground, allowing direct interaction.

Examples:

  • fg %2: Bring the second background job to the foreground
  • fg %emacs: Bring the background emacs job to the foreground
  • fg: Bring the most recent background job to the foreground

jobs - Display status of jobs in the current session

jobs lists the active jobs in the current shell session.

Examples:

  • jobs: List all jobs
  • jobs -l: List jobs with process IDs
  • jobs -p: List only process IDs of the active jobs

nohup - Run a command immune to hangups

nohup allows a command to continue running after the user logs out.

Examples:

  • nohup long_running_script.sh &: Run a script that continues after logout
  • nohup command > output.log 2>&1 &: Run a command, redirecting output and errors
  • nohup python script.py &: Run a Python script that persists after terminal closure

screen - Terminal multiplexer

screen creates a virtual terminal that can be detached and reattached, allowing sessions to persist.

Examples:

  • screen: Start a new screen session
  • screen -S session_name: Start a named screen session
  • screen -r: Reattach to a detached screen session
  • screen -list: List available screen sessions

tmux - Terminal multiplexer

tmux, like screen, allows for persistent terminal sessions and window management.

Examples:

  • tmux: Start a new tmux session
  • tmux new -s session_name: Create a named tmux session
  • tmux attach -t session_name: Attach to an existing session
  • tmux ls: List active tmux sessions

top - Display and update sorted information about processes

top provides a dynamic real-time view of running system processes.

Examples:

  • top: Display system processes, updating every 3 seconds
  • top -u username: Show processes for a specific user
  • top -p 1234,5678: Monitor specific processes by PID

ps - Report a snapshot of current processes

ps displays information about a selection of the active processes.

Examples:

  • ps aux: Display detailed information about all processes
  • ps -ef: Show all processes in full format
  • ps --sort=-%cpu: List processes sorted by CPU usage (descending)

pstree - Display a tree of processes

pstree shows the running processes as a tree, which is helpful for understanding process relationships.

Examples:

  • pstree: Display process tree
  • pstree -p: Show process IDs along with the tree
  • pstree -u: Show user names for each process

uptime - Show how long the system has been running

uptime displays the current time, system uptime, number of users, and load average.

Examples:

  • uptime: Display system uptime and load
  • uptime -p: Show uptime in a pretty format
  • uptime -s: Display the system up since time

pgrep - Look up or signal processes based on name and other attributes

pgrep looks through the currently running processes and lists the process IDs which match the selection criteria.

Examples:

  • pgrep firefox: List PIDs of firefox processes
  • pgrep -u root: List PIDs of processes owned by root
  • pgrep -l sshd: List PIDs and names of sshd processes

kill - Send a signal to a process

kill sends a signal to a process, by default the TERM signal to request termination.

Examples:

  • kill 1234: Send SIGTERM to process with PID 1234
  • kill -9 5678: Send SIGKILL to forcefully terminate process 5678
  • kill -l: List available signals

pkill - Signal processes based on name and other attributes

pkill looks up processes based on name and other attributes and sends them a signal.

Examples:

  • pkill firefox: Send SIGTERM to all firefox processes
  • pkill -9 httpd: Send SIGKILL to all httpd processes
  • pkill -u username: Terminate all processes owned by username

killall - Kill processes by name

killall sends a signal to all processes running any of the specified commands.

Examples:

  • killall nginx: Terminate all processes named nginx
  • killall -9 apache2: Forcefully kill all apache2 processes
  • killall -u username bash: Kill all bash processes for a specific user