# Need generic command to get complete running process details

**URL:** <https://community.unix.com/t/need-generic-command-to-get-complete-running-process-details/365935>\
**Category:** Shell Programming and Scripting\
**Created:** [April 3, 2017, 1:23pm UTC](https://community.unix.com/t/need-generic-command-to-get-complete-running-process-details/365935 "2017-04-03T13:23:17Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![mohtashims](https://community.unix.com/letter_avatar/mohtashims/32/6_449c533f586939b6e5f246632a46421f.png) [@mohtashims](https://community.unix.com/u/mohtashims)\
**Post date:** [April 3, 2017, 1:23pm UTC](https://community.unix.com/t/need-generic-command-to-get-complete-running-process-details/365935/1 "2017-04-03T13:23:17Z")

</div>

I am on SunOS and Linux

I need generic command to get complete process details from which i will eventually extract socket details (listen address and port)

```nohighlight
ps -ef | ggrep -i server | ggrep -i mydomain

```

does not yield a process that should have both the `grep` entries along with the listen address and port.

I need a command generic in Solaris and Linux which also prints the socket details.

If generic is not possible i will appreciate individual ps command for linux and SunOS that gives me the detailed ps output including the socket details.

Can you please help ?

---

<div class="post-metadata">

**Author:** ![Chubler\_XL](https://community.unix.com/user_avatar/community.unix.com/chubler_xl/32/2077_2.png) [@Chubler\_XL](https://community.unix.com/u/Chubler_XL)\
**Post date:** [April 3, 2017, 4:57pm UTC](https://community.unix.com/t/need-generic-command-to-get-complete-running-process-details/365935/2 "2017-04-03T16:57:55Z")

</div>

What does the command line you are searching for look like in linux and SunOS?

I'm guessing that ggrep is a GNU grep you have installed on SunOS.

Have you considered using netstat to find listening processes, eg: `netstat -pln | grep -i server | grep -i mydomain`

---

<div class="post-metadata">

**Author:** ![drysdalk](https://community.unix.com/letter_avatar/drysdalk/32/6_449c533f586939b6e5f246632a46421f.png) [@drysdalk](https://community.unix.com/u/drysdalk)\
**Post date:** [April 3, 2017, 5:58pm UTC](https://community.unix.com/t/need-generic-command-to-get-complete-running-process-details/365935/3 "2017-04-03T17:58:35Z")

</div>

Hi,

Unfortunately, this may be far less straightforward for Solaris than you might be hoping. As Chubler\_XL has pointed out, on Linux you can use a variant of `netstat -lnp` or `netstat -anp` to easily see which processes are responsible for which network connections. So on Linux, this is easy.

For Solaris, however, it all depends on what version you're running. If you're lucky, and you're running 11.2 or later, then the `netstat` command was extended in 11.2 to include this kind of functionality, which up until then it had entirely lacked. Try `netstat -aun` for approximately similar output that will let you see the PID attached to each network connection.

If you're running pre-11.2...well. It gets messy, I'm afraid. Basically, what you have to do is use the `pfiles` command to list the files open for each process ID on the system, and grep for `AF_INET` in the output. If any lines are returned, then you can on a per-process basis extract the sockets that PID is responsible for that way.

If anyone knows of a better way on pre-11.2 to do this I'm sure they'll chime in (and I'd love to know myself), but to the best of my knowledge those are your options for Solaris.

Hope this helps, somewhat !

---

<div class="post-metadata">

**Author:** ![mohtashims](https://community.unix.com/letter_avatar/mohtashims/32/6_449c533f586939b6e5f246632a46421f.png) [@mohtashims](https://community.unix.com/u/mohtashims)\
**Post date:** [April 3, 2017, 9:42pm UTC](https://community.unix.com/t/need-generic-command-to-get-complete-running-process-details/365935/4 "2017-04-03T21:42:14Z")

</div>

> [@drysdalk](#):
>
> Hi,
> 
> Unfortunately, this may be far less straightforward for Solaris than you might be hoping. As Chubler\_XL has pointed out, on Linux you can use a variant of `netstat -lnp` or `netstat -anp` to easily see which processes are responsible for which network connections. So on Linux, this is easy.
> 
> For Solaris, however, it all depends on what version you're running. If you're lucky, and you're running 11.2 or later, then the `netstat` command was extended in 11.2 to include this kind of functionality, which up until then it had entirely lacked. Try `netstat -aun` for approximately similar output that will let you see the PID attached to each network connection.
> 
> If you're running pre-11.2...well. It gets messy, I'm afraid. Basically, what you have to do is use the `pfiles` command to list the files open for each process ID on the system, and grep for `AF_INET` in the output. If any lines are returned, then you can on a per-process basis extract the sockets that PID is responsible for that way.
> 
> If anyone knows of a better way on pre-11.2 to do this I'm sure they'll chime in (and I'd love to know myself), but to the best of my knowledge those are your options for Solaris.
> 
> Hope this helps, somewhat !

None of the suggestions worked ☹

```plaintext
netstat -pln | ggrep -i server | ggrep -i mydomain
netstat: illegal option -- l
usage: netstat [-anv] [-f address_family]
       netstat [-n] [-f address_family] [-P protocol] [-g | -p | -s [interval [count]]]
       netstat -m [-v] [interval [count]]
       netstat -i [-I interface] [-an] [-f address_family] [interval [count]]
       netstat -r [-anv] [-f address_family|filter]
       netstat -M [-ns] [-f address_family]
       netstat -D [-I interface] [-f address_family]
bash-3.2$ cat
^C
bash-3.2$ netstat -aun | ggrep -i server | ggrep -i mydomain
netstat: illegal option -- u
usage: netstat [-anv] [-f address_family]
       netstat [-n] [-f address_family] [-P protocol] [-g | -p | -s [interval [count]]]
       netstat -m [-v] [interval [count]]
       netstat -i [-I interface] [-an] [-f address_family] [interval [count]]
       netstat -r [-anv] [-f address_family|filter]
       netstat -M [-ns] [-f address_family]
       netstat -D [-I interface] [-f address_family]

```

```plaintext
 uname -a
SunOS mymac 5.10 Generic_150400-40 sun4v sparc sun4v

```

By the way before i can use `pfiles ` how can i get the PID becoz the `ps ` command in the OP does not yield extensive output so `ggrep ` fails to yield any output.

---

<div class="post-metadata">

**Author:** ![drysdalk](https://community.unix.com/letter_avatar/drysdalk/32/6_449c533f586939b6e5f246632a46421f.png) [@drysdalk](https://community.unix.com/u/drysdalk)\
**Post date:** [April 4, 2017, 2:04am UTC](https://community.unix.com/t/need-generic-command-to-get-complete-running-process-details/365935/5 "2017-04-04T02:04:25Z")

</div>

Hi,

You're on Solaris 10 (SunOS 5.10 in that `uname` output), so it makes sense that `netstat` can't do what you need here.

If you manually look at the output of `ps -ef` yourself, do you see the process you're looking for ? If not, then you won't be able to grep for it. If you don't see the process you're looking for, do you see the full range of normal processes you'd expect to see on a Solaris system, or do you only see a handful of processes at all ?

Lastly, do you know if this Solaris system has been set up to use zones ? If it has, are you running your `ps` command either inside the same zone as the process you're looking for or from within the global zone ? You'd have to be doing one of those two things to see it if your process is running inside a zone - you wouldn't see it from a different non-global zone, for example.

---

<div class="post-metadata">

**Author:** ![mohtashims](https://community.unix.com/letter_avatar/mohtashims/32/6_449c533f586939b6e5f246632a46421f.png) [@mohtashims](https://community.unix.com/u/mohtashims)\
**Post date:** [April 4, 2017, 8:34am UTC](https://community.unix.com/t/need-generic-command-to-get-complete-running-process-details/365935/6 "2017-04-04T08:34:10Z")

</div>

> [@drysdalk](#):
>
> Hi,
> 
> You're on Solaris 10 (SunOS 5.10 in that `uname` output), so it makes sense that `netstat` can't do what you need here.
> 
> If you manually look at the output of `ps -ef` yourself, do you see the process you're looking for ? If not, then you won't be able to grep for it. If you don't see the process you're looking for, do you see the full range of normal processes you'd expect to see on a Solaris system, or do you only see a handful of processes at all ?
> 
> Lastly, do you know if this Solaris system has been set up to use zones ? If it has, are you running your `ps` command either inside the same zone as the process you're looking for or from within the global zone ? You'd have to be doing one of those two things to see it if your process is running inside a zone - you wouldn't see it from a different non-global zone, for example.

I was able to get the pid using `fuser` and from the pid i get the listen address and port using `pfiles` on SunOS. But i do not know if both the `fuser ` and `pfiles ` will work on Linux.

---

<div class="post-metadata">

**Author:** ![drysdalk](https://community.unix.com/letter_avatar/drysdalk/32/6_449c533f586939b6e5f246632a46421f.png) [@drysdalk](https://community.unix.com/u/drysdalk)\
**Post date:** [April 4, 2017, 8:43am UTC](https://community.unix.com/t/need-generic-command-to-get-complete-running-process-details/365935/7 "2017-04-04T08:43:39Z")

</div>

Hi,

The basic idea is to step through every PID on the system, run `pfiles` against it, and if any of the output lines contain `AF_INET` then those are the sockets that PID has open.

Here's a quick example script I've written. Caveats: this was tested on Tribblix, an illumos distribution, rather than "proper" Solaris, so to speak (since that's what I'm running on my current workstation). But it worked for me, and should work on Solaris 10 as well.

```nohighlight
#!/bin/bash
for pid in `/usr/bin/ps -aef -o pid`
do
        if /usr/bin/pfiles $pid 2>/dev/null | /usr/bin/grep AF_INET 2>/dev/null
        then
                echo Above sockets belong to PID $pid
                echo -----
        fi
done

```

Run this and you'll get the idea. Hope this helps.

---

<div class="post-metadata">

**Author:** ![mohtashims](https://community.unix.com/letter_avatar/mohtashims/32/6_449c533f586939b6e5f246632a46421f.png) [@mohtashims](https://community.unix.com/u/mohtashims)\
**Post date:** [April 4, 2017, 10:23am UTC](https://community.unix.com/t/need-generic-command-to-get-complete-running-process-details/365935/8 "2017-04-04T10:23:19Z")

</div>

> [@drysdalk](#):
>
> Hi,
> 
> The basic idea is to step through every PID on the system, run `pfiles` against it, and if any of the output lines contain `AF_INET` then those are the sockets that PID has open.
> 
> Here's a quick example script I've written. Caveats: this was tested on Tribblix, an illumos distribution, rather than "proper" Solaris, so to speak (since that's what I'm running on my current workstation). But it worked for me, and should work on Solaris 10 as well.
> 
> ```plaintext
> We are good with SunOS.
> 
> Like it said before the only thing pending is to have a pfiles alternate command on Linux inorder to get the IP and port socket details.
> #!/bin/bash
> for pid in `/usr/bin/ps -aef -o pid`
> do
> if /usr/bin/pfiles $pid 2>/dev/null | /usr/bin/grep AF_INET 2>/dev/null
> then
> echo Above sockets belong to PID $pid
> echo -----
> fi
> done
> 
> ```
> 
> Run this and you'll get the idea. Hope this helps.

---

<div class="post-metadata">

**Author:** ![drysdalk](https://community.unix.com/letter_avatar/drysdalk/32/6_449c533f586939b6e5f246632a46421f.png) [@drysdalk](https://community.unix.com/u/drysdalk)\
**Post date:** [April 4, 2017, 10:35am UTC](https://community.unix.com/t/need-generic-command-to-get-complete-running-process-details/365935/9 "2017-04-04T10:35:27Z")

</div>

Hi,

For Linux, you can do basically the same thing either with `netstat` (as per Chubler\_XL's original reply) or `lsof` . So commands like

```nohighlight
lsof -n -iTCP -sTCP:ESTABLISHED

```

or

```nohighlight
netstat -anpt | grep ESTABLISHED

```

would work on Linux to show you the PIDs that currently have TCP network connections active.
