How do I close a program from the terminal

65,381

Now every file is handled by another program say gedit and folders the same, so to kill [ the program handling that file or folder ] we can use two methods:

  1. The program name with:

    pkill <name_of_program>
    
  2. use of program PID (process id)

    • find the PID with pgrep <name_of_program>, then
    • kill it with kill <PID>

Information:

man pkill
man kill

Note: When closed this way any unsaved changes will be lost.

Share:
65,381

Related videos on Youtube

Priyansh Saxena
Author by

Priyansh Saxena

Updated on September 18, 2022

Comments

  • Priyansh Saxena
    Priyansh Saxena over 1 year

    Suppose for example vlc media player is running and some directory is also opened in file browser. Now I want to close either the file browser or vlc.

    One way can be to just click on the cross button on the top left hand corner, but how can I do this using terminal commands?

    • Ravexina
      Ravexina almost 7 years
      What do you mean by file or folder? you mean file manager?
    • George Udosen
      George Udosen almost 7 years
      I don't know what you mean but may be your referring to using the kill command in the terminal?
    • karel
      karel almost 7 years
      Possible duplicate of How can I kill a specific X window
  • Chai T. Rex
    Chai T. Rex almost 7 years
    They want the same behavior as clicking "on the cross button on the top left hand corner", which isn't -9, since -9 doesn't give the program the opportunity to close properly like clicking the "cross button".
  • George Udosen
    George Udosen almost 7 years
    @Chait.rex now assuming user has saved their files and kills the app would there be anything wrong in that?
  • theAlexandrian
    theAlexandrian almost 6 years
    @ChaiT.Rex It can be useful when for example program doesn't respond in the GUI and clicking the cross button doesn't close it.