Ps command source.

Dear friends,

I am using SCO Openserver 5.0.7.
Where does the ps -ef command pick the information from? Is it stored in some file?
Also, the ps -ef command or the ps -eo args command displays truncated information. How to get the complete expanded output without truncation?

Thanks in advance

Sabu.

I don't know the SCO Openserver in detail.
But this problem is common to most if not all Unix.
There is a kernel memory access device like /dev/kmem, or a special /proc filesystem that provides access to some selected kernel memory.
Usually the process args are fully known only to the process itself,
while the kernel maintains a common area of all process args that is limited to usually 80 characters.
The ps command accesses the common kernel area, therefore the truncation.
The Solaris OS has "/usr/ucb/ps axww" that (with root rights) visits each process's private memory to provide full args.

Thank you for the quick response.

Is there a way to echo the command lines when executing a script? Actually I want to see the full command of the linker (ld) that the Cobol-85 compiler fires internally while compiling a Cobol-85 code. I was using ps -ef for that.

You could move the ld executable to ld_orig and put a script in it's place that appends $@ to a log file eg:

#!/bin/sh

echo `date` "ld invoked with $@" >> /tmp/ld.log
ld_orig $@

Many bourne-like shells support set -x , which enables tracing. When enabled, the shell will write to standard error the result of all expansions and substitutions, the final form of the command it's about to run.

Alternatively, you can try truss to monitor system call activity, looking for the exec* system call which loads an executable image into a process.

Regards,
Alister

Thanks a lot Chubler_XL for that great idea. The only thing is that the shell script did not work. I wrote a small C program instead, that does the same thing as the script - that is, displaying the parameters using the argv[] variables and then running the actual ld command using the system() function.

Thank you, once again.

Regards

Sabu.

In what way did the shell script 'not work'? It should be possible to do it in shell if you can do it in C.

Some old Unix shells have a bug with $@.
I have seen this work-around:

#!/bin/sh
echo "$0 `date`: ${1+$@}" >> /tmp/ld_log
ld_orig "${1+$@}"

If unknown at all, substitute the $@ stuff with $*

ld_orig $*

$* must be unquoted so has a problem with embedded space characters.

To answer Corona's query, I suppose the Cobol-85 compiler is able to distinguish between a shell script and a compiled code. When run separately, the shell script works just fine, but the Cobol-85 compiler rejects it with a "Cannot execute" error. It just struck me to try the same thing with a compiled code - so I wrote a little C program to just display the command line parameters and then pass on the same to the renamed ld command through the system() function.