- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Fork in shell
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
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
тАО06-29-2001 02:12 AM
тАО06-29-2001 02:12 AM
Fork in shell
Can we use fork in shell script.
Praveen
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-29-2001 02:33 AM
тАО06-29-2001 02:33 AM
Re: Fork in shell
I think you can not use it directly.
Since you usally code
fork .....;
if ( ...
exec ...;
in C, I guess you like to start a process.
This can easyly done with
commandname &
Processid of this process has to be rescued from $! after the call. You can later wait for completition with wait. I use this in a delay loop for offline backups:
shut_down_application
# two hours max offline !
sleep 7200 &
PID=$!
echo $PID > /tmp/waiter.pid
wait $PID
startup_application
When backup is ok it kills the sleep and the application comes up again. When there is trouble with backup, the application starts at the end of my offline-time-window, regardless, what the backup job is doing.
Volker
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-29-2001 03:13 AM
тАО06-29-2001 03:13 AM
Re: Fork in shell
Volker is right here..
another thing you can from the shell is
exec
this will replace your current shell with
and your shell is thus killed.
you might use this to startup some daemons for example
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-29-2001 06:02 AM
тАО06-29-2001 06:02 AM
Re: Fork in shell
Another option if you want something very much like C fork(),exec(),wait(), etc. is to use perl.
It is also very easy to add a signal handler to handle timeout issues in perl.
You should also be aware that in the shell
you can
cmd1 &
cmd2 &
cmd3 &
wait
In this case wait without an argument will
block until all the background processes have finished.
Regards, Clay
- Tags:
- Perl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-29-2001 05:11 PM
тАО06-29-2001 05:11 PM
Re: Fork in shell
If you want the parent to talk to the child, invoke the child as a co-process (|&) and use the -p option for read and print to talk with it. For example:
#!/usr/bin/sh
telnet localhost smtp |&
master=$!
if kill -0 $master
then
# find the first 200 response
while read -p line
do
case $line in
(2*) smtp_ready=1;;
esac
done
else
echo could not contact smtp server
exit 1
fi
if [ $smtp_ready -eq 1 ]
then
# SMTP dialog using read -p and print -p
fi
# gracefully terminate the child...
if kill -0 $master
then
print -p quit
kill $master
wait $master
fi
I pulled this out of the air, so please excuse any syntax or logical errors.