1

I am asked to check and shut down the processes that I am not familiar with. So when I ls under bin folder, I see multiple process .sh. But I want to know which process is associated with which tomcat process.

Is there any easy way to find out that?

Example startmyprocess1.sh, but when I do ps -ef | grep startmyprocess1 doesn't return the running process.

But actually the running tomcat process name is myprocess, so when I do ps -ef | grep myprocess, I can see the running process. To know that I have to ask the responsible person.

So, the names are different. If like that, I need to ask him several times. Any better way to figure this out?

3
  • I'm not sure what you are really asking for here.. What do you mean by 'checking'? If you want to grep the name of the script use ps l | grep startmyprocess1. Commented Jul 16, 2012 at 11:08
  • For the process you figured out you can try if grep myprocess startmyprocess1.sh gives you some pointers. If the scripts are build by the same person, it is very likely you can find the same line in the other scripts too. Commented Jul 16, 2012 at 18:20
  • hi all, for my case, I only know startmyprocess1.sh script. but I don't know that script is running for the process myprocess. How can I know startmyprocess1.sh is running for myprocess? Commented Jul 17, 2012 at 1:44

5 Answers 5

2

try this one..,(not tested)

ps -aux | grep "yourprocess"

For example,

ps -aux | grep "httpd"
1
  • On MacOS it's ps aux | grep "yourprocess" instead of ps -aux ... . Commented Jan 7, 2019 at 22:59
1

Starting myprocess from within startmyprocess.sh does not name the process after the underlying shell script, that is why your ps -ef | grep startmyprocess1 does not return a result.

This is also why many processes, especially daemons, write their pid out to file so that you can easily reference it's process. This can be done with:

#!/bin/sh
pid=`myprocess`
echo $pid > /tmp/myprocess.pid

or you can query $! which contains the last pid:

#!/bin/sh
myprocess
echo $! > /tmp/myprocess.pid

and query/list the process by it's pid:

ps --pid $PID
0

I think software like "top" will done great work.

Type:

top

or

htop
0

Try the following approach

ps -ef | grep startmyprocess1.sh

Fetch the Parent PID for startmyprocess1.sh, then use below command to find out the parent process from it's PID.

ps -ef | grep *PPID*
0

Answer from @invert has explained a lot, shell script just executes commands within it. What's that means is, you won't get your shell script name at output of top or htop, which just prints the /proc/$PID/cmdline of each routine within the shell script.

Besides using echo $! after command to get the PID of what you want. I'd like to use pgrep command when I need to(or pkill if you would like to kill it).

pgrep, pkill - look up or signal processes based on name and other attributes

The pgrep simply grep your arguments via /proc/*/cmdline and output matching PIDs The pkill is compatiable with kill, so you can easily pkill any routine with the cmdline

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.