- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- question regarding background process 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
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
12-14-2003 09:18 PM
12-14-2003 09:18 PM
question regarding background process in shell
I just want to know the advantages and disadvantages of a process running in back ground. In a script, I found the following piece of code which I did not get the logic behind...
#!/bin/sh
while true do
sleep 5 >/dev/null&
bgpid=$!
wait $bgpid
done
What will be the difference if I write the above code as ...
#!/bin/sh
while true do
sleep 5 >/dev/null
done
any advantage of having sleep in background and waiting for the process to terminate? Will there be any problem if I make sleep in the current shell and remove the wait??? Please clarify...
Regards
VJ.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2003 09:25 PM
12-14-2003 09:25 PM
Re: question regarding background process in shell
There is really no difference in this script, but looks like a test for a real script.
What was its name ?
Base question is: what is the purpose of a script, that do only sleep ??
Massimo
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2003 09:25 PM
12-14-2003 09:25 PM
Re: question regarding background process in shell
If you rewrite the code as suggested it will behave exactly the same.
The original code runs a background process and then waits for it to complete - absolutely pointless.
The reason to run things in background is so that you can do some other processing while the background job executes. Maybe your original script used to do this but got changed along the way, that's the only explanation I can think of.
-- Graham
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2003 09:32 PM
12-14-2003 09:32 PM
Re: question regarding background process in shell
Thnx alot for the quick responce. My only doubt is will there be aby difference in the utilisation of the resources when a command is run in bg/fg?
Will assign points without fail.
Regards
VJ.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2003 09:40 PM
12-14-2003 09:40 PM
Re: question regarding background process in shell
The only difference is that with a background job, the shell continues processing commands (until it does a "wait").
There is the potential to start several background jobs simultaneously, which, if each is resource intensive, could cause problems, but with a trivial thing like sleep, there is no issue.
-- Graham
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2003 09:42 PM
12-14-2003 09:42 PM
Re: question regarding background process in shell
In back ground process are running in less priority then in foreground.
Sunil
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2003 09:48 PM
12-14-2003 09:48 PM
Re: question regarding background process in shell
But we are talking about infinitesimals....
Massimo
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2003 09:55 PM
12-14-2003 09:55 PM
Re: question regarding background process in shell
But as the script only sleeps its not worth the bother.
I dont think you need to send output from sleep to /dev/null as there should be none
John.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2003 10:05 PM
12-14-2003 10:05 PM
Re: question regarding background process in shell
As far as I remember, in the shell, "wait" takes a job number not a process ID or it takes no argument thus "waiting" for all child processes to finish.
Having said that, I think the intention is to demonstrate the "wait" command but I think "sleep" is a bad example of where it might be useful. Also, redirecting output to /dev/null seems a bit dramatic to me and very few people would ever bother to do that.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2003 10:08 PM
12-14-2003 10:08 PM
Re: question regarding background process in shell
the job-id you are mentioning is used with the commands fg and the other job control if any other command :)
Massimo
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2003 10:13 PM
12-14-2003 10:13 PM
Re: question regarding background process in shell
I have to say that it would seem to make sense to use a PID bearing in mind that that is what you prbably want, however I just checked man sh-posix and I get this
wait [job]
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2003 10:18 PM
12-14-2003 10:18 PM
Re: question regarding background process in shell
So, i think that there are both the bulti-in command wait and the external command wait..
Look at this:
yomodvts:/var/mail> which wait
/usr/bin/wait
yomodvts:/var/mail> typeset wait
yomodvts:/var/mail> type wait
wait is a shell builtin.
yomodvts:/var/mail> file /usr/bin/wait
/usr/bin/wait: commands text
yomodvts:/var/mail> more /usr/bin/wait
#!/usr/bin/sh
# @(#) $Revision: 72.2 $
# This is the execable version of wait utility implemented
# using posix shell built-in wait command.
wait $@
exit $?
#################################
I didn't ever checked it before ,
sorry :(
We both were perfectly right.
Massimo
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2003 10:21 PM
12-14-2003 10:21 PM
Re: question regarding background process in shell
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2003 10:32 PM
12-14-2003 10:32 PM
Re: question regarding background process in shell
Can anyone help me how to find memory used for a particular process???
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2003 10:47 PM
12-14-2003 10:47 PM
Re: question regarding background process in shell
I use backgound processes in a shell, when there is a chance, that the command issued may hang, like in my case ftp. I wait, see the return codes in the log file and after five minutes I terminate frp and start from scratch.
You can see the size of a process by:
UNIX95= ps -eo pid,ppid,sz
greetings,
Michael
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2003 10:54 PM
12-14-2003 10:54 PM
Re: question regarding background process in shell
I think you need to realise that unix is elegant. The only reason anything runs in the foreground at all is because processes open the terminal as their standard input and the shell thinks it would be a good idea to wait for them to finish. If you use the "&", the shell decides not to wait for it and the standard input is closed.
This means that resource wise, the two are almost identical.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2003 10:56 PM
12-14-2003 10:56 PM
Re: question regarding background process in shell
Look in the "sz" col of "ps -l"
"man ps" for more info.
-- Graham
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2003 11:31 PM
12-14-2003 11:31 PM
Re: question regarding background process in shell
If you have the 'sleep' running in the foreground, any kill signal passed to the shell will be processed AFTER sleep exits. In the case where the shell is waiting for the background process signals will be processed IMMEDIATELY.
Of course, this matters only if your script has been written to process signals in some way e.g. trap 'whatever' n
Regards,
John