Quick Tip: Check the output of a running command

Have you ever wished to peek inside a running command with Linux?

Well I did today, I had a Python project that should start on boot, and I wished to check it was running. So I ran a command to see if the process was running.

ps -ef | grep soil-uv.py  

This command lists all the processes running and using the | pipe to send it to grep meant that I could search for the name of the file soil-uv.py.

The output of the command gave me this...

root       403   375  0 14:13 ?        00:00:00 /bin/sh -c /home/pi/soil-uv.py  
root       405   403  0 14:13 ?        00:00:06 /usr/bin/python3 /home/pi/soil-uv.py  
pi         995   788  0 14:36 pts/0    00:00:00 grep --color=auto soil-uv.py  

So I can see that my Python project code is running and it has a process id of 405.

But...I want to see what it is doing!

So using tail I can see the output from the code.

sudo tail -f /proc/405/fd/1  

The -f means "follow" the output of the process, and I then pass the parameter to follow process 405 and show the output in the terminal...and I got this!!

The soil value is 0.38  
UV Index:        1.39  
The soil value is 0.38  
UV Index:        1.39  
The soil value is 0.38  
UV Index:        1.39  
The soil value is 0.38  
UV Index:        1.4  
The soil value is 0.38  
UV Index:        1.39  

Which is the output of my code! Just what I wanted to do!

sysadminHAPPYDANCE!