Process concept
Process is an instance of a program that has started executing but has not yet terminated. Program is a file that contains executable code. A process is created from a program; it is a running entity that consumes system resources. A process is not the same as a program. Process types: interactive process, batch process, daemon process. Relationship: multiple processes can originate from the same program (many-to-one).
Viewing processes
Command syntax: ps [options]
Options:
- -A : show information for all processes on the system (same as -e).
- -a : show information for all user processes.
- -f : full-format listing with all process details.
- -l : long format.
- -r : show only running processes.
- -u : user-oriented format (includes username, CPU and memory usage, etc.).
- -x : show processes not attached to a controlling terminal.
- -p : show information for the specified process ID(s).
- -t : show processes associated with the specified terminal.
Viewing process inheritance (pstree)
The pstree command displays the process inheritance tree. The tree is rooted at init by default or at the specified pid. If a user is specified, the tree shows only processes owned by that user.
Syntax: pstree [options] [pid|user]
Options:
- -a : show command line arguments; processes swapped out are shown in parentheses.
- -c : do not compact identical subtrees (by default identical names may be prefixed with *).
- pid|user : use the specified pid as the root or show processes owned by the specified user.
Process termination
- kill [signal] pid
- killall [signal] process_name
- Use ps -aux to list processes.
- Use pstree to view child processes.
Process scheduling
Delayed scheduling (at)
- Purpose: run a specified program at a specified time.
- Format: at [-f file] [-m] time
- -f : specify a file that contains the commands to be scheduled.
- -m : send mail to the user who executed the at command when the job finishes. time: the time to execute the job; absolute or relative formats are supported.
- Absolute formats: MMDDYY or MM/DD/YYYY, or use today or tomorrow.
- Relative format: now+num+time_unit, where time_unit can be minutes, hours, days, weeks.
- Examples: at now+1 minutes at> echo "hell" > /dev/pts/2 (press Enter) Ctrl+D to end the at entry at -f file 17:30+2 days
Periodic scheduling (cron / crontab)
- Purpose: schedule recurring tasks.
- crontab -u user {-e | -l | -r}
- -u : operate on the specified user's crontab
- -e : edit the crontab for the user
- -l : list the user's crontab (defaults to current user)
- -r : remove the user's crontab
- crontab -u user file (install the crontab from file for the user)
- Crontab file format: minute hour day month day-of-week run_command
- Examples: crontab -u username -e # edit/create the crontab 00 00 */3 * * /path/to/command [args]
- crontab -l # view current user's crontab
- crontab -u user -r # remove user's crontab
- Field meanings: minute hour day month weekday command Time field values: * : any value in the field , : list of values - : range of values / : step values
- Examples: Mon-Fri at 17:00 0 17 * * 1-5 Mondays, Wednesdays, Fridays at 08:30 30 8 * * 1,3,5 Every 2 hours between 08:00 and 18:00 0 8-18/2 * * * Every 3 days 0 * */3
Crontab spool location
/var/spool/cron/root