The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



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

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 03-13-2007
scotbuff scotbuff is offline
Registered User
  
 

Join Date: Jun 2005
Location: Middletown, PA
Posts: 73
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.
  #2 (permalink)  
Old 03-13-2007
matrixmadhan matrixmadhan is offline Forum Advisor  
Technorati Master
  
 

Join Date: Mar 2005
Location: leaf node in B+ tree
Posts: 2,958
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!
  #3 (permalink)  
Old 03-13-2007
scotbuff scotbuff is offline
Registered User
  
 

Join Date: Jun 2005
Location: Middletown, PA
Posts: 73
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.
  #4 (permalink)  
Old 03-13-2007
matrixmadhan matrixmadhan is offline Forum Advisor  
Technorati Master
  
 

Join Date: Mar 2005
Location: leaf node in B+ tree
Posts: 2,958
Am surprised,

why is that there isnt tusc (system call tracer for HP-UX) available ?
  #5 (permalink)  
Old 03-13-2007
scotbuff scotbuff is offline
Registered User
  
 

Join Date: Jun 2005
Location: Middletown, PA
Posts: 73
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.
Closed Thread

Bookmarks

Tags
linux commands

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 04:32 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0