Home COMSC-171 <- Prev Next ->

Processes & Jobs

Job Control

more /etc/passwd # don't page through the file; stay on the first screen Ctrl+z # this will suspend more and return to the shell less /etc/fstab # again don't page through the file Ctrl+z # suspend less most /etc/services # again don't page through the file Ctrl+z # suspend pg ps # shows your processes with Process IDs jobs # shows background jobs with status and job numbers # + indicates current job, - indicates previous job fg # this will bring the current job [3] to the foreground Ctrl+z # suspended it again fg 2 # this will bring job [2] to the foreground (%2 also works) Ctrl+z # suspended it again %1 # this will bring job [1] to the foreground Ctrl+z # suspended it again %pg # this will show the job named pg Enter # bring it to the foreground Ctrl+z # suspended it again

Processes

# open another terminal window, connect, and login again tty # this will show the name of the tty (terminal) for this session ps # this will show your processes in the current session ps ax # shows all processes (BSD options without -) ps U $USER # shows all processes of a specified user (BSD) ps u # user listing format (BSD) ps l # long listing format (BSD) ps -e # shows every process (UNIX options use -) ps -f # full format (UNIX) ps -u $USER # shows all processes of a specified user (UNIX)

Signals

kill -l # (lowercase L) list available signals ps -u $USER # remember the PID (number) of pg kill -9 PID # (PID is the number above) ps -u $USER # you have killed pg in the other session jobs # this will only show jobs in the current shell (none)

Process Filesystem (Linux, deprecated in FreeBSD)

ls -F /proc # filesystem interface to kernel data, numbered entries for processes ps # remember the PID (number) of your bash process ls -F /proc/PID # (PID is the number above) info for your bash process cat /proc/sys/kernel/pid_max # max PID, FreeBSD equivalent sysctl kern.maxproc

Background

# click in the other terminal window delay.tcl 120 & # tcl script (not part of UNIX) which waits for 120 seconds # & will put delay.tcl in the background jobs fg Ctrl+c # terminate delay.tcl

Other Terminal

tty ps -u $USER # remember the PID (number) of the other shell (on the other tty) kill -9 PID # (PID is the number above) send kill signal to shell in other session ps -u $USER # you're logged out of other session

Nohup

nohup delay.tcl 300 & # runs TCL script in the background even after logout ps -u $USER logout # gives error message if you have stopped jobs logout # repeating the command will log you out anyway # login again jobs # the new shell has no background jobs ps -u $USER # delay.tcl still running, remember its PID kill -9 PID # (PID is the number above) ps -u $USER # delay.tcl is gone

Related Commands

pstree
show processes as a tree
top
interactive processes display
killall
sends signals to process names rather than to process IDs
pkill, pgrep
combine functions of ps, grep, kill to search for processes and send signals