![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| ps | grep command not returning existing process | jlitzie | UNIX for Advanced & Expert Users | 6 | 07-20-2007 09:58 AM |
| Getting the process full command line | fredy | AIX | 0 | 12-21-2006 03:06 AM |
| process command | tonoche | UNIX for Dummies Questions & Answers | 2 | 09-28-2004 11:31 PM |
| need script to process ls-l command | sinner | Shell Programming and Scripting | 12 | 04-15-2004 05:36 PM |
| trying to read batch process but need some command help | etravels | Shell Programming and Scripting | 1 | 11-19-2003 10:48 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Process ID of Command
I need a way to get the Process ID of the last command I executed in a script. Not the last background process but the last command.
For example, suppose I am executing a binary inside a script like so. binary.program argument1 argument2 If this binary program runs fast, is there a command that will tell me the last PID of that command. In other words, can I get the PID of a command I execute within a shellscript? Is my only alternative to get information like this by running the process in the background and using "$!"? Any thoughts are appreciated. Thanks in advance. |
|
||||
|
You could do that with system call tracer, in Linux available as strace on Solaris as truss commands take this sample, Code:
>cat script.zsh #! /bin/zsh ./while exit 0 while binary is nothing but, endless loop Code:
#include <stdio.h>
int main()
{
while(1) {
}
return 0;
}
Run it as, strace zsh script.zsh > out.log 2>&1 And now in the out.log strace would have traced system call of the script which spawned the binary within it, it would be available as the return value of clone system call. In the out.log it should be something like, Code:
clone(parameters) = return value; Return value above is the pid of the binary ( child ) spawned by the script ( parent ) Try it out!
|
|
||||
|
Interesting
I like your alternative, however I unfortunately need to make this work on HP-UX out of the box. So I do not have trace or tusc available on this server so I cannot use this method. Thanks for the reply, I will keep digging and see if I can find another solution. Thanks again.
![]() |
|
||||
|
I know
Well, tusc is not default, it is something that has to be installed extra. I am not a sysadmin on this box so I cannot make the call of adding it. Since what I was trying to do would go elsewhere, I have to also assume the HP-UX box sitting elsewhere would also not have tusc installed.
|
![]() |
| Bookmarks |
| Tags |
| linux commands |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|