- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Looking for alternate to the “exec” command
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
Forums
Discussions
Discussions
Discussions
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
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
01-30-2009 01:53 PM
01-30-2009 01:53 PM
Solved! Go to Solution.
- Tags:
- exec
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-30-2009 02:02 PM
01-30-2009 02:02 PM
Re: Looking for alternate to the “exec” command
Run each process in the background:
#!/usr/bin/sh
process1 &
PID1=$!
process2 &
PID2=$!
...
The shell special vairable '$!' is the PID of the last process placed in the background. See the 'sh-posix' manpages for more information.
Regards!
...JRF...
- Tags:
- background
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-30-2009 02:26 PM
01-30-2009 02:26 PM
SolutionPerhaps this example will help:
# cat ./proc.sh
#!/usr/bin/sh
./proc_1 &
PID1=$!
./proc_2 &
PID2=$!
echo "...two processes started -- ${PID1} ${PID2}"
wait ${PID1}
echo "process-1 ${PID1} done with rc=$?"
wait ${PID2}
echo "process-2 ${PID2} done with rc=$?"
# cat ./proc_1
#!/usr/bin/sh
sleep 20
exit 1
# cat ./proc_2
#!/usr/bin/sh
sleep 10
exit 0
# ./proc.sh
...two processes started -- 14061 14062
process-1 14061 done with rc=1
process-2 14062 done with rc=0
...That is, you can do synchronous work; wait for all processes to terminate; and interrogate the return code of each process when it terminates.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-30-2009 02:29 PM
01-30-2009 02:29 PM
Re: Looking for alternate to the “exec” command
Define "procedures". Shell scripts?
I'm confused (which is not unusual). Can you
supply a test case? I'd expect any program
or script which is run by a top-level shell
script to get its own process to wreck. I
would not expect it to wreck its parent
process. Now, if you did
. script2
instead of (plain)
script2
then _that_ could cause trouble if "script2"
contained an "exec" (because then it would
not be run in its own process).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-03-2009 11:01 AM
02-03-2009 11:01 AM
Re: Looking for alternate to the “exec” command
I'm using the exec command in a shell script. The script starts a database client connection which runs a batch job. The command line in the script looks like this: exec $PATH/bin/_prog (plus all the stuff required to run the batch against a specific database).
file _prog
_prog: ELF-64 executable object file - PA-RISC 2.0 (LP64)
existing script:
- set a path, term and environment variables
- change to a working directory
- exec $PATH/bin/_prog (launch db client connection for processing batch_A)
modification I wish to achieve:
- set a path, term and environment variables
- change to a working directory
- exec $PATH/bin/_prog (launch db client connection for processing batch_A)
-- validate results of batch_A
-- conditionally run exec $PATH/bin/_prog (launch db client connection for processing batch_B)
The script never gets to the validation step since exec launches in the current process. According to the man pages on my system it looks like this is the expected behavior:
man exec
The exec*() system calls, in all their forms, load a program from an ordinary, executable file into the current process, replacing the current program.
I've tested the same script without the exec command ($PATH/bin/_prog instead of exec $PATH/bin/_prog) and the script completes. This proves the issue is the exec command AND that I should verify dropping the exec command as a solution with our application provider. So far I have not discovered any adverse affects. I'd still like to find a shell scripting solution that allows the use of the exec command and satisfies my end to start dependency.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-03-2009 11:09 AM
02-03-2009 11:09 AM
Re: Looking for alternate to the “exec” command
> ...I should verify dropping the exec command as a solution with our application provider. So far I have not discovered any adverse affects. I'd still like to find a shell scripting solution that allows the use of the exec command and satisfies my end to start dependency.
I showed you how to start multiple processes in a shell script and wait() for their completion. This is probably the simplest way to create synchronous processes and control/wait/test their execution. Have you evaulated my suggestion as originally posted?
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-03-2009 12:53 PM
02-03-2009 12:53 PM
Re: Looking for alternate to the “exec” command
I rearranged your examples to meet my needs:
# cat ./proc.sh
#!/usr/bin/sh
exec ./proc_1 &
PID1=$!
wait ${PID1}
echo "process-1 ${PID1} done with rc=$?"
if [ $? -eq 0 ]
then
exec ./proc_2 &
PID2=$!
wait ${PID2}
echo "process-2 ${PID2} done with rc=$?"
else
exit
fi
Excellent solution. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-03-2009 01:10 PM
02-03-2009 01:10 PM
Re: Looking for alternate to the “exec” command
Why not simplify and just do:
I rearranged your examples to meet my needs:
# cat ./proc.sh
#!/usr/bin/sh
./proc_1
echo "process-1 done with rc=$?"
if [ $? -eq 0 ]
then
./proc_2
echo "process-2 done with rc=$?"
else
exit
fi
The 'exec' and 'wait' seem superfluous in this context since you just want to make sure proc_1 completes with RC=0 before starting proc_2.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-03-2009 01:32 PM
02-03-2009 01:32 PM
Re: Looking for alternate to the “exec” command
I'm glad to have helped.
You do _NOT_ need to 'exec' the process at all. It is much clearer to the reader of your script if you don't. Simply do:
./proc_1 &
...as I originally showed. RUnning in the background enables you to spawn mutliple processes synchronously.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-04-2009 08:17 AM
02-04-2009 08:17 AM
Re: Looking for alternate to the “exec” command
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-04-2009 08:18 AM
02-04-2009 08:18 AM