Processes in Linux


#1

I am using Inspec to test a process running on the Linux system. However, even though the process is running, it still shows that it doesnt exist. I checked the source code for the processes resource and saw that they run the ps axo command and extract the 11 field to the command parameter. However, my process is preceded by grep --color=auto. Hence it is actually grep which is adding to the 11th field. Is there any workaround to this problem?


#2

Hi @poornimas,

As workaround you could use the command resource
https://www.inspec.io/docs/reference/resources/command/


#3

as @simark said you could use command resource.!!!

For Example:
describe command('ps -ef | grep chef-client') do
    its('exit_status') { should eq 0 }
end 

#4

Yea. Thanks… That works.


#5

I think you need to remember to grep out the grep, otherwise it will always find “chef-client” in the ps query:

aspitzer@jumpnt1:~/ > ps -ef | grep chef-client
aspitzer 14214 61615 0 14:40 pts/29 00:00:00 grep chef-client
aspitzer@jumpnt1:~/ > echo $?
0

aspitzer@jumpnt1:~/ > ps -ef | grep -v grep | grep chef-client
aspitzer@jumpnt1:~/ > echo $?
1


#6

The “pgrep” and “pkill” tools are you rfriends for organizing this kind of process detection and parsing.


#7

Yup. I realized that too. The process is actually not running. It is just the grep that was being displayed.