# Find memory usage along with time

**URL:** <https://community.unix.com/t/find-memory-usage-along-with-time/326582>\
**Category:** UNIX for Advanced & Expert Users\
**Created:** [April 3, 2013, 6:31am UTC](https://community.unix.com/t/find-memory-usage-along-with-time/326582 "2013-04-03T06:31:16Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![PikK45](https://community.unix.com/letter_avatar/pikk45/32/5_5575768a8748004e209b776fc1b2916d.png) [@PikK45](https://community.unix.com/u/PikK45)\
**Post date:** [April 3, 2013, 6:31am UTC](https://community.unix.com/t/find-memory-usage-along-with-time/326582/1 "2013-04-03T06:31:16Z")

</div>

Hi Guys,

I have a script. It calls an executable inside (programmed in C). I will have to find the execution time of that script and amount of memory consumed by that process as well.

```nohighlight
#!/bin/sh

echo "Script starting"

echo "executable staring"
executable parm1 parm2 parm3
echo "executable completed"

echo "Script completed"

exit

```

I know `time ./script.sh` will give me the execution time of this. What I would want to know is the total memory(RAM) and %CPU utilized by this as well.

System Details:  
HP-UX  
B.11.23

---

<div class="post-metadata">

**Author:** ![Yoda](https://community.unix.com/user_avatar/community.unix.com/yoda/32/2498_2.png) [@Yoda](https://community.unix.com/u/Yoda)\
**Post date:** [April 3, 2013, 10:12am UTC](https://community.unix.com/t/find-memory-usage-along-with-time/326582/2 "2013-04-03T10:12:19Z")

</div>

Capture the PID of your executable, then use `ps` to check CPU & MEM:

```nohighlight
UNIX95=1 ps -ef -o pid,pcpu,vsz,comm | grep <PID>

```

---

<div class="post-metadata">

**Author:** ![PikK45](https://community.unix.com/letter_avatar/pikk45/32/5_5575768a8748004e209b776fc1b2916d.png) [@PikK45](https://community.unix.com/u/PikK45)\
**Post date:** [April 3, 2013, 11:51am UTC](https://community.unix.com/t/find-memory-usage-along-with-time/326582/3 "2013-04-03T11:51:24Z")

</div>

`-o` Not recognized...!!! ☹ ☹

---

<div class="post-metadata">

**Author:** ![Yoda](https://community.unix.com/user_avatar/community.unix.com/yoda/32/2498_2.png) [@Yoda](https://community.unix.com/u/Yoda)\
**Post date:** [April 3, 2013, 12:01pm UTC](https://community.unix.com/t/find-memory-usage-along-with-time/326582/4 "2013-04-03T12:01:09Z")

</div>

Yes, `-o` is an illegal option when you simply run `ps` on HP-UX.

So you have to set UNIX95 variable to use the XPG4 environment instead of the HP-UX environment.

```nohighlight
$ UNIX95=1 ps -ef -o pid,pcpu,vsz,comm | grep init
    1 0.40 852 init
   23 0.05 0 pagetableinit_daemon

```

```nohighlight
$ uname
HP-UX

```

---

<div class="post-metadata">

**Author:** ![PikK45](https://community.unix.com/letter_avatar/pikk45/32/5_5575768a8748004e209b776fc1b2916d.png) [@PikK45](https://community.unix.com/u/PikK45)\
**Post date:** [April 4, 2013, 5:51am UTC](https://community.unix.com/t/find-memory-usage-along-with-time/326582/5 "2013-04-04T05:51:26Z")

</div>

Thanks, Yoda 🙂

```nohighlight
pid -- process id
pcpu -- CPU utility%
vsz -- memory usage? in KB or MB?
comm -- command

```
