-3

Final result of the finite tasks in the background:

( wget google.com && zenity --info || zenity --error ) & PID=$!
...if ... kill $PID ...zenity ...

Why will not he act? How should it be good?

[edit:] Fixed, thanks.

1 Answers1

1

With what you posted, wget get started in the background, but zenity doesn't, it runs right after wget has been started. So it has no chance at all of getting wget's return value: wget hasn't completed yet!

Try something like:

( wget google.com  && zenity --info || zenity --error ) &
PID=$!
if ... kill $PID ...zenity ...
Mat
  • 202,337
  • 40
  • 393
  • 406
  • As early as I did, I did not work. I jumped out the error: > kill: (8524) - No such process ps-f displays: > arney 8526 8061 0 10:14 pts/0 00:00:00 wget google.com The Fedora is ok. I do not understand Ubuntu. I have to remove and install Fedora. Thank you again. – user1365064 May 01 '12 at 08:19
  • Changing distributions for that is simply not a good idea, you'll get the exact same behavior on Fedora (or SuSE, or Gentoo, or...) Are you sure you put the parenthesis and & exactly as above? – Mat May 01 '12 at 08:21
  • I want to achieve: >>> ( ( wget google.com && true > files || echo "no" > files ) & echo > PID ) | zenity --progress --pulsate --auto-close || kill "`cat PID`" ; [ ! -s files ] && zenity --info || zenity --error <<< Is unable to otherwise free parentheses. – user1365064 May 01 '12 at 08:41
  • Sometimes the process can die just before you try to kill it. – Mat May 01 '12 at 08:56
  • I agree, but sometimes wget is different id than the variable $PID, np. wget = 1250, $PID = 1252. Then there is no chance to kill the wget. – user1365064 May 01 '12 at 11:31
  • The pid you get should be the pid of the subshell that runs wget if you use the syntax I put above. That shouldn't die before wget has died, and should kill wget if you kill it. – Mat May 01 '12 at 11:33