Showing posts with label process. Show all posts
Showing posts with label process. Show all posts

Wednesday, April 04, 2007

Finding and Killing a Process in GNOME

There are a few different ways to find and kill a process in Linux. Using the GNOME interface, you can call up the System Monitor (similar to the one on Windows XP) under System->Administration->System Monitor. Under the Processes tab, right clicking on a process will give you a variety of options: stop/end/kill/continue the process, change the priority (nice), display a memory map (pmap) and display open files (lsof -p <procID>).

Embedding the system monitor in a desktop panel is useful for constantly monitoring the system and quickly determining if and where there is a problem. Do this with Right Click on Panel->Add to Panel...->System & Hardware->System Monitor->Add. The display provides graphs of Processor, Memory, Network, Swap Space, Hard disk and Load activity (not quite sure what load is, perhaps some metric computed from all the others? I don't use it, personally).

On the command line, list processes with the ps command or ps -e for all users' processes. Pipe that through grep (i.e., ps -e | grep firefox) to find a process ID of the target process (if you know the exact name of the program, you can also use pidof firefox-bin). To kill a process, use the kill <procID> command (with the -9 flag if you want to kill it unconditionally). Alternatively, if the process uses a gui, you can use xkill to merely click on the gui to kill the corresponding process. There is also killall if you want to kill by process table name (i.e. killall firefox-bin).

pgrep and pkill are two very useful utilities, especially for dealing with processes with long command line invocations. pgrep -fl -u danny "ruby.*asdf" will print the process id and name of every process owned by danny whose command line invocation matches the passed in regular expression. The -f argument tells it to match against the full command line invocation instead of just the process name. pkill -fu dannyc "ruby.*asdf" will kill those same processes (for the life of me, I can't seem to coax similar behavior out of killall).

The top command provides an integrated way of finding and killing a process on the command line. If the process-to-be-killed is using a lot of system resources, it will appear towards the top of the display. Hit k and then the process ID to kill the process. Top comes with a lot of other functionality -- hit h for help.

UPDATE: I recommend using htop instead of top, which is top with less suck. It has lots of good features like color, mouse support, a more responsive interface, a tree-based process view, etc.

Saturday, January 20, 2007

UNIX status commands on Solaris

Proc tools:
  • pflags Print the /proc tracing flags, the pending and held signals, and other /proc status information for each lwp in each process.
  • pcred Print or set the credentials (effective, real, saved UIDs and GIDs) of each process.
  • pldd List the dynamic libraries linked into each process, including shared objects explicitly attached using dlopen(3C). See also ldd(1).
  • psig List the signal actions and handlers of each process. See signal.h(3HEAD).
  • pstack Print a hex+symbolic stack trace for each lwp in each process.
  • pfiles Report fstat(2) and fcntl(2) information for all open files in each process. In addition, a path to the file is reported if the information is available from /proc/pid/path. This is not necessarily the same name used to open the file. See proc(4) for more information.
  • pwdx Print the current working directory of each process.
  • pstop Stop each process (PR_REQUESTED stop).
  • prun Set each process running (inverse of pstop).
  • pwait Wait for all of the specified processes to terminate.
  • ptime Time the command, like time(1), but using microstate accounting for reproducible precision. Unlike time(1), children of the command are not timed.
Other commands:
  • arch display system architecture (i86pc)
  • uname print name of current system (SunOS)
  • pagesize display the size of pages of memory
  • iostat report I/O stats for terminal, disk, tape, etc
  • vmstat report virtual memory statistics
  • mpstat report CPU statistics
  • busstat report bus-related support statistics
  • lsof list open files (sockets (lsof -i), etc.) Introductory lsof examples
  • nohup run a command immune to hangups
  • kstat display kernel statistics
While navigating manpages, note that Solaris uses more to view them, which is supremely annoying. Use less with export PAGER="less" (tip found here).