Process management

From English Wiki
Jump to navigation Jump to search

The following are common commands and utilities for process management in Linux.


1 Process management

Command Function
at -d job ID Cancels scheduled job according to job ID; equivalent to atrm
at -l cmd Lists scheduled jobs; equivalent to atq
at time cmd Runs a command at a specified time
bg Moves a running process to the background.
bpytop A new top alternative (requires installation)
cmd & Start a process and send it to the background
crontab -e Edit crontable
crontab -l List scheduled tasks
crontab -r Remove crontable
df Display information on system disks, e.g., free and used storage
dmesg -k Outputs system messages (helpful for troubleshooting)
dmesg -k Display system messages
fg Brings the most recent background job to the foreground
fg PID Brings a job to the foreground
free Display information about RAM and swap, free and used memory.
fuser Show which processes are using a particular file, device, or system resource
fuser -m /dev/sda1 Show which processes are using a particular device
history Print a history list of all commands issued within a particular shell
htop Display all running processes in real time (alternative to top)
jobs List all jobs presently running
journalctl System logs
journalctl _UID=1000 View log entries for a specific user by user ID
journalctl --since "­YYY­Y-MM-DD HH:MM" --until "­YYY­Y-MM-DD HH:MM" Filter and display log entries for a certain time period
journalctl -f Follow system logs in real time
journalctl -u httpd -n 3 View 3 log entries for httpd
journalctl -u sshd View log entries for only SSH
kill Terminate a running process.
kill -1 OR -15 Soft kill a process
kill -2 Interrupt process; equivalent to CTL-c
kill -9 Kill a process forcefully and immediately
kill -l List kill signal names
kill PID Kills a running process of a specified process ID.
killall procname Kill all processes of the specified name
lsof List all files opened by running processes
lsof Display currently open files
nice Grant execution rights to a process with an assigned priority.
nohup Allow a process to continue after logging out
pidof Shows the process ID of a specified process.
pidof procname Find the PID of a process
ps Display currently running processes
ps -ef Display all active processes
grep procname Display information on a specific process
ps aux Display information on running processes in BSD format
ps PID Display the status of a running processes by its process ID
pstree Display processes in the tree-like diagram
renice Change or alter the execution priority of an already running system process
renice -5 PID Adjust priority level of a running process by process ID
script Record terminal session activity and create output for the session in a file
sensors Outputs the system's CPU temperature
stop|restart Used for managing system services through an executable sysV init script. You can start, stop, or restart the specified system service.
systemctl status service Change the status of a service managed by systemctl
time Print time taken for a command to finish running
top Manage and display all processes in real time
whereis Show locations of binary, source and manual pages for a command
which program Show the commands associated with an application


2 Rsync

Command Function
rsycn -av –exclude ‘*.txt’ /src_dir/ /dest_dir Archive but exclude a specific file type
rsync -av --max-size=1000m src_dir/ dest_dir/ Archive but exclude files over a certain size
rsync -av –exclude ‘dir’ /src_dir/ /dest_dir Archive but exclude a specific directory from the source location
rsync -av /src_dir/ dest_dir Archival backup (recursively, preserving links and file attributes; v=verbose)
rsync -avR /a/b/xyz.c remote:/tmp/ Archive a file on a remote machine, preserving the relative path (e.g., creating /tmp/a/b/xyz.c)
rsync -avz /src_dir/ /dest_dir Archive as a compressed file
rsync /source_dir/ /desitnation_dir OR source_dir/ destination_dir/ Backup a directory to a different location


3 Crontab

Crontab is a utility to schedule and automate processes and commands. To get started setting up Crontab to automate processes, you can invoke the editor and do some general management like so. If you've set up a command and want to end the process, you need to open up the crontab editor, delete the entry, and save the crontab file (saving it will restart the crond daemon). The cron editor on many systems may use the vi editor by default, and some experienced users insist one should use vi.

Command Function
crontab -e Edit crontab file
EDITOR=nano crontab -e Specify an editor like nano to edit the crontab file
crontab -l List the scheduled crontab jobs
crontab -r Remove the crontab file
crontab -v Display the last time the crontab file was edited


In the crontabe editor, the following crontab syntax is used to set up automatic processes. The columns are in the following owrder:

  1. Command
  2. Minute (0-59)
  3. Hour (0-23, 0=midnight)
  4. Day of the month (1-31)
  5. Month (1-12)
  6. Day of the week (0-6, 0=Sunday)


Min (0-59) Hour (0-23) Day/month (1-31) Month (1-12) Day of week (0-6; Sunday=0) Command #Explanation
* * * * * * #Default (Null contents when first starting crontab)
0 20 * * * rm /home/user/dir/* #Remove files from a specified directory every day at 8pm
30 * * * * rm /home/user/dir/* #Removes contents of a specified directory every our on the half hour
0 0 1 * * rsynch -azv /home/user/ /bk/user #Automated archival backup of a user’s home directory every month (at midnight at the start of each month)
0 0 * * 0 rsynch -azv /home/user/ /bk/user #Automated archival backup every Sunday at midnight
0 22 * * 1-5 rsynch -azv /home/user/ /bk/user > /dev/null 2>&1 #Automated archival backup at 10pm every weekday; then prevent crontab from sending an email to the user account (by default, cron sends an email after executing each command)
0 0 * * * rsynch -azv /home/user/ /bk/user > /home/users/crontlogs/cron.log #Automated archival backup; and log each job in a file


4 See also