Operating System - HP-UX
1753971 Members
8533 Online
108811 Solutions
New Discussion юеВ

Re: question regarding background process in shell

 
Mark Grant
Honored Contributor

Re: question regarding background process in shell

Massimo,

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]

Never preceed any demonstration with anything more predictive than "watch this"
Massimo Bianchi
Honored Contributor

Re: question regarding background process in shell

Mark: i checked the man page, and it turned out to be wait [pid].


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 Grant
Honored Contributor

Re: question regarding background process in shell

Isn't it nice when we can both be right :)

Never preceed any demonstration with anything more predictive than "watch this"
vasundhara
Frequent Advisor

Re: question regarding background process in shell

Thanks alot for all the responces. I just want to check at least one resouce utilisation factor for both cases mentioned above. For example, how much memory will be used when its run in bg/fg.

Can anyone help me how to find memory used for a particular process???
Michael Schulte zur Sur
Honored Contributor

Re: question regarding background process in shell

Hi,

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 Grant
Honored Contributor

Re: question regarding background process in shell

The difference between these two on memory consumption is going to be so tiny, I can't see how you would measure it. The first one is slightly longer and therefore requires slightly more memory though possibly not and I guess the shell allocates memory is chunks anyway so the difference probably doesn't exist.

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.
Never preceed any demonstration with anything more predictive than "watch this"
Graham Cameron_1
Honored Contributor

Re: question regarding background process in shell

>>Can anyone help me how to find memory used for a particular process???

Look in the "sz" col of "ps -l"

"man ps" for more info.

-- Graham
Computers make it easier to do a lot of things, but most of the things they make it easier to do don't need to be done.
John Palmer
Honored Contributor

Re: question regarding background process in shell

Actually there is a subtle difference between the two, how the shell handles signals.

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