How to Display Full Process Path/Name in Linux Top Command for Rails/Puma/Apache Processes


3 views

When monitoring Rails production servers, you'll notice an inconsistency between what ps and top show for your application processes. While ps -AF displays helpful descriptive names like:

ubuntu  12345  0.0  2.1 123456 78900 ?  Sl   Jan01  43:00 Rails: /var/www/myapp/current

The same process appears as just ruby in top, making it difficult to identify specific applications when multiple Rails instances are running.

This difference occurs because:

  • ps shows the full command line by default (including arguments)
  • top traditionally truncates the process name to just the executable name
  • Ruby/Rails processes launch as ruby executables with the application path as an argument

Here are several approaches to show full process information in top:

Method 1: Using Top's Interactive Commands

While top is running:

Press 'c' to toggle command line display
Press 'f' then enable 'COMMAND' column

Method 2: Launching Top with Full Command Display

top -c

Or make this the default by adding to your ~/.bashrc:

alias top='top -c'

Method 3: Using htop Instead

Install the more feature-rich htop:

sudo apt install htop
htop

Method 4: Custom PS Output

For a ps output that resembles top's display but with full process info:

ps -eo pid,user,pcpu,pmem,cmd --sort=-pcpu | head

To make these changes permanent:

  1. Create or edit ~/.toprc
  2. Add these configuration lines:
RCfile for "top with windows"       # shameless bullshit line
Id:a, Mode_altscr=0, Mode_irixps=1, Delay_time=3.000, Curwin=0
Def     fieldscur=AEHIOQTWKNMbcdfgjplrsuvyzX
        winflags=32569, sortindx=10, maxtasks=0
        summclr=1, msgsclr=1, headclr=3, taskclr=1

For Rails-specific monitoring:

# Show memory usage per Rails process
ps -eo pid,user,pcpu,pmem,rss,cmd --sort=-rss | grep -E 'Rails|ruby|puma'

# Alternative with pstree
pstree -p $(pgrep -f 'Rails|puma')

When monitoring Rails applications on Ubuntu, many developers notice a discrepancy between process naming in different tools. While ps -AF shows descriptive process names like:

00:00:43 Rails: /var/www/myapp

The standard top command only displays:

ruby

This makes it difficult to identify specific Rails processes when monitoring system resources.

The difference occurs because:

  • ps -AF shows the full command line including arguments
  • Default top configuration only displays the executable name

Here's how to modify top's behavior:

# Method 1: Temporary solution (lasts until next top launch)
1. Launch top
2. Press 'c' to toggle command line display

# Method 2: Permanent solution
1. Create or edit ~/.toprc
2. Add these lines:
   RCfile for "top with windows"       # We skipped version 3.07
   idle:a
   Def fieldscur=AEHIOQTWKNMbcdfgjplrsuvyzX
   winflags=64777
   sortindx=18
   maxtasks=0
   summclr=1
   msgsclr=1
   headclr=3
   taskclr=0

For a more user-friendly experience, consider htop:

sudo apt install htop
htop

htop shows full process names by default and allows easy customization:

F2 → Display options → Check "Display command in full"

For Rails-specific monitoring, create a custom configuration:

# ~/.rails_toprc
RCfile for "top with windows"
Def fieldscur=AEHIOQTWKNMbcdfgjplrsuvyzX
winflags=64777
sortindx=18
summclr=1
taskclr=0
delay=3.0

Then launch with:

top -c -n 1 -b | grep -E 'Rails|ruby'

For complex deployments with multiple apps, use this script:

#!/bin/bash
watch -n 5 "ps -AF | grep -E 'Rails|Passenger' | grep -v grep"

Save as railsmon.sh and make executable:

chmod +x railsmon.sh
./railsmon.sh

If running under systemd, you can get process information with:

systemctl status your-rails-service | grep PID
ps -AF --pid YOUR_PID