Unix Programming - Capturing the process id of an executing program

This is Interesting: Free IT Magazines  
Home > Archive > Unix Programming > July 2005 > Capturing the process id of an executing program





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Capturing the process id of an executing program
MarkG

2005-07-19, 7:49 am

Hi all,

My first posting - hope someone can help.

I am trying to write a shell script that runs one of my own programs
and I want to capture the process id, store it in a text file exit from
the script and then have another script run some time later which reads
the pid and kills the job.

I have tried unsuccessfully to use the 'ps' command from within the
script that starts the program - the reason being that I cannot
discriminate confidently between processes and therefore be sure I am
deleting the right process. This is because the same program could be
used by more than one user and all scripts are run under the same user
account by these users.

I have also tried another technique such as this: -

#!/bin/jsh
myprogram &
echo $! > .pidlog
fg

I thought this would work, but after getting errors, I have been told
that
job control commands cannot be used non-interactively. This is
essential to my app since all the scripts are executed from a Windows
based GUI - no terminal windows are used.

Surely, this problem has already been solved without the use of COTS
tools?

Thanks in anticipation,
Mark G.

alexs

2005-07-19, 5:54 pm



MarkG wrote:
> Hi all,
>
> My first posting - hope someone can help.
>
> I am trying to write a shell script that runs one of my own programs
> and I want to capture the process id, store it in a text file exit from
> the script and then have another script run some time later which reads
> the pid and kills the job.
>
> I have tried unsuccessfully to use the 'ps' command from within the
> script that starts the program - the reason being that I cannot
> discriminate confidently between processes and therefore be sure I am
> deleting the right process. This is because the same program could be
> used by more than one user and all scripts are run under the same user
> account by these users.
>
> I have also tried another technique such as this: -
>
> #!/bin/jsh
> myprogram &
> echo $! > .pidlog
> fg
>
> I thought this would work, but after getting errors, I have been told
> that
> job control commands cannot be used non-interactively. This is
> essential to my app since all the scripts are executed from a Windows
> based GUI - no terminal windows are used.
>
> Surely, this problem has already been solved without the use of COTS
> tools?
>
> Thanks in anticipation,
> Mark G.


Something like:

nohup myprogram &
echo $! > pid

MarkG

2005-07-20, 2:49 am

Apologies - after posting question realised I should really have posted
to the shell programmers group so have posted their as well.

Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com