Tuesday, August 07, 2007

Disowning Processes

Exiting from a shell while having background processes can sometimes cause these processes to exit.

To Avoid this, the process must be disowned. If the job is already started, it can be disowned by typing 'disown %' where is the number as listed by the jobs command.

Alternatively, you can start the process by simply putting the whole string in brackets. For example, if you wanted to start the process true, in the background and disowned, you could type:

(/bin/true &)

Labels: , , ,

Backgrounding Processes

Processes run from the command line in a shell such as bash can be placed in to the background in 2 ways:

1. Placing an '&' after the command. This starts to process in the background automatically.

2. Press Control+Z (Ctrl+Z) after the job has started. This gives you the chance to enter any text you may need to, before moving on. By Pressing Ctrl+Z, you actually suspend the process. Typing 'bg' will background the process.

You can bring a process back in to the foreground by typing 'fg'.

If you have multiple jobs running in the background, you can view them by typing 'jobs'. To bring a job in to the foreground (which was not the last one), use 'fg %' the is the same one listed in the output from the 'jobs' command.

Labels: , , ,