- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Child passing exit code to parent
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-28-2003 10:10 AM
тАО07-28-2003 10:10 AM
Child passing exit code to parent
Thanx
Brian Pyle
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-28-2003 10:26 PM
тАО07-28-2003 10:26 PM
Re: Child passing exit code to parent
Are you looking for 'wait'?
Or are you using straight 'sh'? (and not Bash).
Cristi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-29-2003 12:34 AM
тАО07-29-2003 12:34 AM
Re: Child passing exit code to parent
Perhaps what you are looking for is semaphore...
It is difficult in a sense not to use a file as everithing in Unix is a file, semaphore is also a file but it lives in memory, I have never used theses in a program myself, I have only managed then, that is added some to kernel parameters ..
for oracle and/or applications
But if you do a man -k semaphore you should be able to work it out from there.
Hope this is of use.
Jean-Pierre
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-29-2003 03:57 AM
тАО07-29-2003 03:57 AM
Re: Child passing exit code to parent
Maybe I'm misunderstanding what you're trying to do. But if the child process is a shell script, you should be able to execute:
exit n
where 'n' is the return code you want to pass back to the parent. In the parent script, you would do something like this:
child.sh
rc=$?
echo "rc = $rc"
This would display the return code passed back via the 'exit' statement.
HTH,
Tom
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-29-2003 05:37 AM
тАО07-29-2003 05:37 AM
Re: Child passing exit code to parent
eg.
while [ $count -lt 10 ]
do
run_script=`child_script &`
child_pid_list=$child_pid_list,$!
(($count=$count+1))
done
while [ more_children -gt 0 ]
do
"somehow check child status or exit"
"do something based on that exit"
sleep 10
done
Thanx
Brian
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-29-2003 05:40 AM
тАО07-29-2003 05:40 AM
Re: Child passing exit code to parent
Brian
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-29-2003 09:41 AM
тАО07-29-2003 09:41 AM
Re: Child passing exit code to parent
code of the child process that terminated.
You can use "wait" two ways:
wait
wait job
The first form waits for all child processes
and returns the exit code from the last one
that exited. Probably not useful for you,
because you want the codes from all the
child processes.
The second form waits for a specific job
and returns its exit code. This is closer
to what you want, but requires you do wait
for them in order.
What you really need is something like the
C call wait(), which waits for any child
process to finish and returns its error
code. Unfortunately, I don't think the
sh-posix "wait" has that capability. To
do what you want I think you'll have to
go to C or Perl.
HTH
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-29-2003 10:44 PM
тАО07-29-2003 10:44 PM
Re: Child passing exit code to parent
parent.sh:
----
count=1
declare -a child_pid_array
while [ $count -lt 10 ]
do
./child.sh $$ &
pid=$!
echo "Spawned $pid"
###result=`wait $pid &`
echo $result
child_pid_array[$count]=$pid
((count=$count+1))
echo "$count: $child_pid_array, ${child_pid_array[$count]}"
done
running=9
while [ $running -gt 0 ]
do
sleep 1
count=1
running=9
echo ----------------------
while [ $count -lt 10 ]
do
if [ -d /proc/${child_pid_array[$count]} ]
then echo "$count still running"
else
echo "${child_pid_array[$count]} dead"
((running=$running-1))
fi
((count=$count+1))
done
echo "$running running"
done
----
and child.sh
----
#!/bin/sh
sleeptime=`echo "$RANDOM/1000" | bc`
sleep $sleeptime
echo "Process $$ Exiting with status $sleeptime" > "/proc/$1/fd/1"
exit $sleeptime
----
Only half solved as it will tell you if the child processes are still alive. Status is sent via a fd so that's bad.
The commented wait call in the parent script will never work because when a job is started in the background it is not child of the shell that started it.
Here's what i'm talking about:
(pstree just after running the parent process)
[diciu@bluefish tmp]$ pstree
init-+-anacron
|-atd
|-bdflush
|-cardmgr
|-8*[child.sh---sleep] <<<<<< CHILD
|-crond
[..]
|-mdrecoveryd
|-6*[mingetty]
|-sshd
|-syslogd
|-xdm-+-X
| `-xdm---.Xclients-defau-+-bbrun
| |-fluxbox-+-mozilla-bin
| | |-sylpheed
| | |-xterm---bash---su---bash
| | |-xterm---bash---man---sh---sh-+-l+
| | | `-n+
| | `-xterm---bash--- <<< PARENT
and the parent call to wait will result in:
Spawned 1678
./parent.sh: line 1: wait: pid 1678 is not a child of this shell
So I guess the only thing that stands is job management but I have no idea if the works programatically (ie without Ctrl+Z to put something in background).
Cheers
Cristi