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 here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Parent child Relation !! using awk/sed ??? varungupta UNIX for Advanced & Expert Users 0 01-29-2008 11:24 AM
exiting a child without stopping the parent madpenguin Shell Programming and Scripting 5 09-19-2007 07:45 PM
kill parent and child larry UNIX for Dummies Questions & Answers 4 01-11-2003 09:18 PM
How hard can it be? ps child/parent velde046 Filesystems, Disks and Memory 2 05-25-2002 01:36 PM
what are parent and child processes all about? xyyz UNIX for Dummies Questions & Answers 1 04-26-2002 12:53 PM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 05-31-2006
Registered User
 

Join Date: May 2005
Posts: 15
Parent/Child Processes

Hello.
I have a global function name func1() that I am sourcing in from script A. I call the function from script B. Is there a way to find out which script called func1() dynamically so that the func1() can report it in the event there are errors?

Thanks
Reply With Quote
Forum Sponsor
  #2  
Old 05-31-2006
blowtorch's Avatar
Supporter
 
Join Date: Dec 2004
Location: Singapore
Posts: 2,326
I don't think that you can do that through a command. May be something like this?
Code:
# cat test.sh
#!/usr/bin/ksh

func1() {
        echo global function
        echo $(ps -ef |awk -v pid=$$ '{if($2==pid) print $NF}') has run func1
}
Code:
# cat test1.sh
#!/usr/bin/ksh

. ./test.sh
echo $0 is running
func1
echo $0 is ending
Code:
# ./test1.sh
./test1.sh is running
global function
./test1.sh has run func1
./test1.sh is ending
Here test.sh holds the global function, test1.sh 'sources' test.sh via the '. ./' mechanism.

Note: on Solaris, please use nawk instead of awk.

Last edited by blowtorch; 05-31-2006 at 09:12 AM. Reason: adding Solaris note
Reply With Quote
  #3  
Old 05-31-2006
Registered User
 

Join Date: May 2005
Posts: 15
Works great!! Thank you.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 11:34 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0