В началоUnix Toolbox → 2. PROCESSES
Gentoo-doc HOME Пред.: Unix ToolboxВ началоУровень выше: Unix ToolboxСлед.: 3. FILE SYSTEM

2. 2. PROCESSES

2.1. 2.1 Listing and PIDs

Each process has a unique number, the PID. A list of all running process is retrieved with ps.

# ps -auxefw # Extensive list of all running process

However more typical usage is with a pipe or with pgrep:

# ps axww | grep cron

586 ?? Is 0:01.48 /usr/sbin/cron -s

# pgrep -l sshd # Find the PIDs of processes by (part of) name

# fuser -va 22/tcp # List processes using port 22

# fuser -va /home # List processes accessing the /home partiton

# strace df # Trace system calls and signals

# truss df # same as above on FreeBSD/Solaris/Unixware

# history | tail -50 # Display the last 50 used commands

2.2. 2.2 Priority

Change the priority of a running process with renice. Negative numbers have a higher priority, the lowest is -20 and "nice" have a positive value.

# renice -5 586 # Stronger priority

586: old priority 0, new priority -5

Start the process with a defined priority with nice. Positive is "nice" or weak, negative is strong scheduling priority. Make sure you know if /usr/bin/nice or the shell built-in is used (check with # which nice).

# nice -n -5 top # Stronger priority (/usr/bin/nice)

# nice -n 5 top # Weaker priority (/usr/bin/nice)

# nice +5 top # tcsh builtin nice (same as above!)

2.3. 2.3 Background/Foreground

When started from a shell, processes can be brought in the background and back to the

foreground with [Ctrl]-[Z] (^Z), bg and fg. For example start two processes, bring them in the background, list the processes with jobs and bring one in the foreground.

# ping cb.vu > ping.log

^Z # ping is suspended (stopped) with [Ctrl]-[Z]

# bg # put in background and continues running

# jobs -l # List processes in background

[1] - 36232 Running ping cb.vu > ping.log

[2] + 36233 Suspended (tty output) top

# fg %2 # Bring process 2 back in foreground

Use nohup to start a process which has to keep running when the shell is closed (immune to hangups).

# nohup ping -i 60 > ping.log &

2.4. 2.4 Top

The program top displays running information of processes.

# top

While top is running press the key h for a help overview. Useful keys are:

• u [user name] To display only the processes belonging to the user. Use + or blank to

see all users

• k [pid] Kill the process with pid.

• 1 To display all processors statistics (Linux only)

• R Toggle normal/reverse sort.

2.5. 2.5 Signals/Kill

Terminate or send a signal with kill or killall.

# ping -i 60 cb.vu > ping.log &

[1] 4712

# kill -s TERM 4712 # same as kill -15 4712

# killall -1 httpd # Kill HUP processes by exact name

# pkill -9 http # Kill TERM processes by (part of) name

# pkill -TERM -u www # Kill TERM processes owned by www

# fuser -k -TERM -m /home # Kill every process accessing /home (to umount)

Important signals are:

1 HUP (hang up)

2 INT (interrupt)

3 QUIT (quit)

9 KILL (non-catchable, non-ignorable kill)

15 TERM (software termination signal)

Пред.: Unix ToolboxВ началоУровень выше: Unix ToolboxСлед.: 3. FILE SYSTEM
В началоUnix Toolbox → 2. PROCESSES