I don't know why it use eval (is it necessary?)and i can't understand the meaning of
[ ! -d "/proc/$!" ] && ((count = TIMEOUT))
besides,the book says that /proc is where information about running process is found,but i can't find the relative directory of my background process.why?
I tried that code. I set TIMEOUT to 7 and I replaced hanging_jobs with "sleep 3" and "sleep 100". The code works fine. I removed the evals and tried it again. Still works fine. While those eval's are harmless, I cannot see any reason to use them. The code
[ ! -d "/proc/$!" ] && ((count = TIMEOUT))
tests to see the the directory is missing. If so it sets count to TIMEOUT. This makes the loop stop.
Not all systems have a /proc filesystem. Maybe yours does not. This undermines to portability of that code. A more portable way to test if a process exists is to use "kill -0 $pid". This won't kill the process but it will fail the process is not there.
If anyone has any thoughts on why those eval's are useful I hope they post. They have me beat.
thanks so much.i thought the "=" to be a equal rather than a assign operator:wall:
my operating system is Linux2.6.35,it has the /proc,but the relative file(directory) of running background process can't be found in it in this example.
yeah,i use the "sleep 10" and i printed the $_ every second and during that period,i checked the /proc and didn't find it. So,in your linux,it works fine?
Could you copy-paste your script exactly as you have it? I think there must be some slight error somewhere that's throwing it off.
background processes are no more special than any other process as far as the kernel's concerned and definitely do appear in /proc/ in any linux I can think of.