Process table names from background functions

Process table names from background functions

am 29.09.2007 03:00:09 von tom

I have a ksh script (we'll call it driver.shl) which sources in a
different script full of functions (func.shl). It then calls a
function (func_a) via the eval command in the background (ie, eval
func_a &). func_a compresses some data, whereas driver.shl allocates
how much data storage is required and reserves a portion by touching
some files that contain the pertininent location and size required by
the parent PID.

When I call ps to see how many occurrences of "driver.shl" are
running, I see the parent, and then all the children which are
actually running my func_a function in the background. Is this
something I can control? Or is this just something inherit in
subprocesses which use functions instead of a different ksh script?


>From what I've read, on AIX, I can't change the name in the process
table.

If I can't change the name, I suppose I can change my logic to only
count the occurrences of "driver.shl" in the process table which do
not have a parent associated with "driver.shl".

Any thoughts / more elegant solutions? This is just more of a hassle
than anything ... but something I would correct if possible.
Currently, this just causes it to wait on PIDs (5 seconds per child
function) then ignores it.

Not sure how much sense that made ... but any help would be
appreciated.
Thanks, Tom

Re: Process table names from background functions

am 29.09.2007 04:33:45 von Barry Margolin

In article <1191027609.325959.280160@d55g2000hsg.googlegroups.com>,
Tom wrote:

> I have a ksh script (we'll call it driver.shl) which sources in a
> different script full of functions (func.shl). It then calls a
> function (func_a) via the eval command in the background (ie, eval
> func_a &). func_a compresses some data, whereas driver.shl allocates

Why do you need to use eval? Can't you just do

func_a &

> how much data storage is required and reserves a portion by touching
> some files that contain the pertininent location and size required by
> the parent PID.
>
> When I call ps to see how many occurrences of "driver.shl" are
> running, I see the parent, and then all the children which are
> actually running my func_a function in the background. Is this
> something I can control? Or is this just something inherit in
> subprocesses which use functions instead of a different ksh script?

The latter. Functions are not separate programs that get executed,
they're just subroutines in the current shell script. Running them in
the background doesn't change that, it just causes them to run in a
subshell.

> >From what I've read, on AIX, I can't change the name in the process
> table.
>
> If I can't change the name, I suppose I can change my logic to only
> count the occurrences of "driver.shl" in the process table which do
> not have a parent associated with "driver.shl".
>
> Any thoughts / more elegant solutions? This is just more of a hassle
> than anything ... but something I would correct if possible.
> Currently, this just causes it to wait on PIDs (5 seconds per child
> function) then ignores it.

I'm not sure what problem you're trying to solve. Why do you need to
know how many driver.shl processes are running?

Does func_a need to be a function? If it were a standalone shell script
it would show up in the process table with its own name.

--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***

Re: Process table names from background functions

am 29.09.2007 05:37:02 von tom

On Sep 28, 9:33 pm, Barry Margolin wrote:
> In article <1191027609.325959.280...@d55g2000hsg.googlegroups.com>,

> Why do you need to use eval? Can't you just do
>
> func_a &

I think we used eval because of some of the parameters that were
passed to it and how we were redirection I/O ... maybe it was
unnecessary anyway.


> The latter. Functions are not separate programs that get executed,
> they're just subroutines in the current shell script. Running them in
> the background doesn't change that, it just causes them to run in a
> subshell.
That was my thought as well.

> > >From what I've read, on AIX, I can't change the name in the process
> > table.
>

> I'm not sure what problem you're trying to solve. Why do you need to
> know how many driver.shl processes are running?
Yes, without the children subshells / subprocesses. Like I mentioned,
I can look to see how many driver.shl programs are being executed that
do not have driver.shl as it's parent ... but it seemed like there
should be an easier approach.

> Does func_a need to be a function? If it were a standalone shell script
> it would show up in the process table with its own name.

I suppose it doesn't have to be a function, that was just the way we
designed it. I suppose it would be pretty easy to dot in the
functions into a different ksh, and call that instead ... like I said,
just something I thought might have an easier answer than that.

Re: Process table names from background functions

am 30.09.2007 04:59:01 von Barry Margolin

In article <1191037022.726217.288440@19g2000hsx.googlegroups.com>,
Tom wrote:

> On Sep 28, 9:33 pm, Barry Margolin wrote:
> > I'm not sure what problem you're trying to solve. Why do you need to
> > know how many driver.shl processes are running?
> Yes, without the children subshells / subprocesses. Like I mentioned,
> I can look to see how many driver.shl programs are being executed that
> do not have driver.shl as it's parent ... but it seemed like there
> should be an easier approach.

I don't understand your response. I didn't ask a yes/no question, but
you answered "yes".

If you need to count certain processes, why not have them update a
counter in a file?

--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***