MQ-Jr
MQ-Jr
unixcop Admin

How to use disown command in Linux

- Advertisement -

Introduction

In the Unix shells ksh, bash, fish and zsh, the disown builtin command is used to remove jobs from the job table Like cd or pwd, it is a shell built-in command, and doesn’t require root privileges, or to mark jobs so that a SIGHUP signal is not sent to them if the parent shell receives it (e.g. if the user logs out).

So, In this tutorial we will cover different ways you can use the disown command in Linux.

Using disown command

  • Syntax of disown command
disown (options) jobID1 jobID2 ...etc
  • To use the disown command, we need to have jobs running on the Linux systems.

For example: we will start up two jobs running in the background

cat /dev/urandom > /dev/null &
ping unixcop.com > /dev/null &
  • Also List your running jobs with the command below:
jobs -l

NOTE:

  1. cat command is denoted by ‘-’, meaning it will become the active job if the ping command is terminated.
  2. ping command is denoted by ‘+’, that means it’s a currently active job.
  • To remove all jobs from the job table, run disown command with -a (refers to all) option as follows:
disown -a
  • Also to remove a specific job from the job table, use the disown command with the job ID you want to terminate. The job ID is listed in brackets on the job table as shown below in the screenshot:
  • For example, We will remove the cat command from jobs table
disown %1
  • To remove the last job on the job table, use the disown command without any options or job IDs as follows:
  • To remove only the jobs currently running, run the command disown with -r option as follows
  • Once you exit your system’s terminal, all currently running jobs are automatically terminated. To prevent this, use the disown command with the -h option:
disown -h (jobID)
  • After you use the disown command, close the terminal
exit
  • Any jobs you used the disown -h command on will keep running.
disown -h

Conclusion

In this tutorial, We illustrated how to use disown command to remove jobs from the job list or keep them running even after you close the terminal window.

Thanks..

- Advertisement -

1 COMMENT

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest articles

Join us on Facebook

x