2

Whenever I want to open a editor from the terminal i write

gedit filename.sh

But in this case i cannot write again in the terminal until and unless I close the editor first.

But whenever I use the command

gedit filename.sh &

It returns a value, like this

enter image description here

and i get my control back over the terminal without closing the editor. I learnt this trick from an youtube video but that guy didnt mentioned why this occurs and what is the number that is being returned. I am a newbie in linux, so this question may be silly to some pros, but still its my doubt and I will be highly obliged if you kindly help me in this. Thank you.

Turing101
  • 143

2 Answers2

4

What you are doing by executing something like gedit filename.sh & is telling your shell to run gedit in the background as a job (as seen by [1] 3842).

BulletBob
  • 1,780
4

Run command in background:

$ sleep 1000 &
[1] 17227

Take a look at output of jobs:

$ jobs -l
[1]  + 17227 running    sleep 1000

You're getting:

  • [1] job number
  • 17227 process id PID

Both ids can be useful in different scenarios. e.g.

Send job to foreground:

$ fg 1

Send job to background:

$ bg 1

Kill job:

$ kill %1

Find out command line of process:

$ ps aux | grep 17227
user      17227   0.0  0.0  4268156    500 s002  TN    3:35PM   0:00.00 sleep 1000

Hope it helps.

Jonas
  • 544