8

I use wget command in the background like this

wget -bq

and it prints

Continuing in background, pid 31754.

But when I type the command jobs, I don't see my job(although the downloading is not finished).

  • 2
    You can see it with ps -p 31754 – pLumo Jan 11 at 13:24
  • Jjobs only works for the (this) shell job control (namely & annotation, ctrl-z or bg commamd). General process listing (ps -a will show it) – eckes Jan 11 at 19:23
19

When using wget with -b or --background it puts itself into the background by disassociating from the current shell (by forking off a child process and terminating the parent). Since it's not the shell that puts it in the background as an asynchronous job, it will not show up as a job when you use jobs.

To run wget as an asynchronous (background) job in the shell, use

wget ... URL &

If you do this, you may additionally want to redirect output to some file (which wget does automatically with -b), or discard it by redirecting to /dev/null, or use -q or --quiet.

  • 1
    it forks a child and the parent exits – user2497 Jan 11 at 13:42
  • @user2497 Yes, see updated answer. – Kusalananda Jan 11 at 15:28
6

Because it put it self in the background. Use & to tell bash to put it into background, and to put it into bash's list of jobs.

Background and job control list are not the same. Bash puts all of its background processes into its jobs control list (by default), but processes can be backgrounded with out being put in the list. Only bash can put jobs in its list.

There may be advantages to the -bg option (I don't know what). For example ssh's background option, puts it into the background after asking for a password.

  • 3
    It's -bq, i.e. -b and -q, not -bg. – Kusalananda Jan 11 at 13:25
2

The process with pid 31754 exists; if you type ps -e |grep 31754 but as it is not a job that can be moved to the foreground again, it is not displayed by the jobs command. wget -bq automatically send the output to the background without options to move it to the foreground again.

  • ps has a -p option that can be used to query a specific PID, or one may use pgrep wget. – Kusalananda Jan 11 at 13:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.