we discussed ruby code where we used
ps -ocommand. In this blog let’s discuss how to get arguments passed to a command.
What is the issue
In the referred blog we are trying to find if
-f argument was passed to the
git push command.
The kernel knows the arguments that was passed to the command. So the only way to find that answer would be to ask kernel what was the full command. The tool to deal with such issues is
In order to play with
ps command let’s write a simple ruby program first.
In terminal execute
ruby sl.rb. In another terminal execute
So here I have two bash shell open in two different tabs in my terminal. First terminal tab is running s1.rb. The second terminal tab is running
ps. In the second terminal we can see the the arguments that were passed to program
ps lists all the processes belonging to the user executing the command and the processes started from the current terminal.
ps -p87070 would show result only for the given process id.
We can pass more than on process id.
ps -o can be used to select the attributes that we want to be shown. For example I want only pids to be shown.
Now I want
I want result only for a certain process id.
Now we have the arguments that were passed to the command. This is the code that article was talking about.
For the sake of completeness let’s see a few more options.
ps -e would list all processes.
ps -f would list a lot more attributes including