Linux close running process

Killing a process in linux [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.

This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.

server01:/# ps -ax | grep java Warning: bad ps syntax, perhaps a bogus '-'? See http://procps.sf.net/faq.html 7342 pts/3 Z 0:00 [java] 7404 pts/3 S+ 0:00 grep java server01:/# kill 7342 server01:/# ps -ax | grep java Warning: bad ps syntax, perhaps a bogus '-'? See http://procps.sf.net/faq.html 7342 pts/3 Z 0:00 [java] 7406 pts/3 S+ 0:00 grep java server01:/# 

In the above I am using ps command to know the pid of the java process which is 7342 in the above case. Then I killed that process using kill command. But that is not killed because again ps command shows java process with pid 7342. Should I use some else command to kill the process and Why kill is not able to kill the process Thanx

7 Answers 7

ps aux

kill -1 PID_NUMBER

to ask program to close itself, if it dosn´t answer you can force it to close

kill -9 PID_NUMBER

remember that using -9 to force program will finalize without asking and not saving anything check: man kill for more details

keep in mind that kill -9 should be your last resort as it doesn’t let child processes of the process you are killing die. so they become zombie processes.

Linux supports the BSD style switches to the ps command (without the leading — . dash/hyphen). If one supplies the hypen then the GNU coreutils version of ps (the one which is standard on mainstream Linux distributions) will attempt to interpret the switches as SysV compatible. This is the source of your error.

I’d recommend using the BSD form of the switches and look up the -o option to specify an output format consisting ONLY of the PID of the matching processes.

Also you’re attempting to kill a zombie. As you’ve discovered that’s a futile effort. A zombie is a placeholder in the process able for a process which is already dead. It remains in the process table until its parent process «reaps» its exit code. If the parent never does a wait() system call then the entry will stay there until after the parent is killed, at which point the zombie (and any other orphaned processes) will be inherited by the init process. The normal init under Linux (or any other form of UNIX) periodically reaps all dead processes (zombies).

Conceptually every process that exits on a UNIX/Linux system spends a small amount of time as a «zombie» . that is there should always be a period of time between the process’ termination and the time when some other process reads its exit value (even if only to discard it, as init does).

Читайте также:  Подключить второй монитор линукс

This question really should go on ServerFault

Источник

How to kill a process or stop a program in Linux

Here are several options for terminating a program in Linux using the command line or a graphical interface.

x sign

Thomas Hawk via Flickr. CC BY-NC 2.0

When a process misbehaves, you might sometimes want to terminate or kill it. In this post, we’ll explore a few ways to terminate a process or an application from the command line as well as from a graphical interface, using gedit as a sample application.

Using the command line/termination characters

Ctrl + C

One problem invoking gedit from the command line (if you are not using gedit & ) is that it will not free up the prompt, so that shell session is blocked. In such cases, Ctrl+C (the Control key in combination with ‘C’) comes in handy. That will terminate gedit and all work will be lost (unless the file was saved). Ctrl+C sends the SIGINT signal to gedit . This is a stop signal whose default action is to terminate the process. It instructs the shell to stop gedit and return to the main loop, and you’ll get the prompt back.

Ctrl + Z

This is called a suspend character. It sends a SIGTSTP signal to process. This is also a stop signal, but the default action is not to kill but to suspend the process.

It will stop (kill/terminate) gedit and return the shell prompt.

Once the process is suspended (in this case, gedit ), it is not possible to write or do anything in gedit . In the background, the process becomes a job. This can be verified by the jobs command.

jobs allows you to control multiple processes within a single shell session. You can stop, resume, and move jobs to the background or foreground as needed.

Let’s resume gedit in the background and free up a prompt to run other commands. You can do this using the bg command, followed by job ID (notice [1] from the output of jobs above. [1] is the job ID).

This is similar to starting gedit with &, :

Using kill

kill allows fine control over signals, enabling you to signal a process by specifying either a signal name or a signal number, followed by a process ID, or PID.

What I like about kill is that it can also work with job IDs. Let’s start gedit in the background using gedit & . Assuming I have a job ID of gedit from the jobs command, let’s send SIGINT to gedit :

Note that the job ID should be prefixed with % , or kill will consider it a PID.

kill can work without specifying a signal explicitly. In that case, the default action is to send SIGTERM , which will terminate the process. Execute kill -l to list all signal names, and use the man kill command to read the man page.

Using killall

If you don’t want to specify a job ID or PID, killall lets you specify a process by name. The simplest way to terminate gedit using killall is:

This will kill all the processes with the name gedit . Like kill , the default signal is SIGTERM . It has the option to ignore case using -I :

 $ gedit & [1] 14852 $ killall -I GEDIT [1]+ Terminated gedit

To learn more about various flags provided by killall (such as -u , which allows you to kill user-owned processes) check the man page ( man killall )

Читайте также:  Ios apps for linux

Using xkill

Have you ever encountered an issue where a media player, such as VLC, grayed out or hung? Now you can find the PID and kill the application using one of the commands listed above or use xkill .

Using xkill

xkill allows you to kill a window using a mouse. Simply execute xkill in a terminal, which should change the mouse cursor to an x or a tiny skull icon. Click x on the window you want to close. Be careful using xkill , though—as its man page explains, it can be dangerous. You have been warned!

Refer to the man page of each command for more information. You can also explore commands like pkill and pgrep .

Источник

How to Find the Process ID of a Program and Kill it in Linux

This tutorial teaches you to kill a process in Linux using both its process id and GUI method. This is particularly helpful in killing unresponsive programs.

You can easily stop a program in Linux terminal by pressing the Ctrl+C keys. But you often need to ‘kill’ an unresponsive program. In Windows, you have the task manager for this situation. In Linux, you can kill a process using the command line or GUI task managers. Using the command line is easier. All you have to do is:

  • Finding the PID and killing a running process in the command line
  • Using the top command to find and kill a process
  • Using task managers in Linux desktop to terminate a running process

Let’s start with the command line first.

Method 1: Terminate a process using the kill command

To kill a process, you must know its process ID (PID). The following section tells you how to find the process ID of a program.

Step 1: Find the PID of a process

If you know the name of the process, you can use the command pidof in this fashion:

You can take the help of the tab completion to find the program’s name. The good thing about this command is that it will give the PIDs of all the processes initiated by the program. Here’s an example:

[email protected]:~$ pidof firefox 8980 8871 8821 7228 3796 3742 3741 3590 3381 3355 3085

Finding process ID of a program

If the pidof command doesn’t result in anything, it could mean either there is no process running of that program or the program name you used is incorrect.

You can try the ps command if unaware of the exact program name. This ps command is used for seeing the running processes on the system. You can use the grep command with the program name (or whatever you remember about it).

ps aux | grep -i “name of your desired program” 

The ps aux command returns all the running processes on the system. And the grep afterward shows the line which matches the program name. The output of the command will be like this:

Find the PID of a process in Linux with ps command

As shown in the picture above, you can get the process ID of the program/process in the second column. Just ignore the line with “–color =auto”.

Читайте также:  Linux mint windows виртуальная машина

Step 2: Kill the process using the PID

Once you have the PID of the desired application, use the following command to kill the process immediately:

Here’s an example where I terminate a running instance of the Nautilus file manager. As you can see, Nautilus was no longer running after it was killed. The grep —color=auto -i nautilus is just the grep command running for nautilus search.

Killing process in Linux command line

You can also use the kill command without option -9. Then it requests the process to terminate. With -9 option, it force kills the process immediately. Read more on sigterm and sigkill.

If you have more than one process id, you can kill them together by providing all the PIDs.

sudo kill -9 process_id_1 process_id_2 process_id_3

You can also combine the kill command and the pidof command to kill all the processes of a program.

sudo kill -9 `pidof programe_name`

Of course, you have to replace the program_name with the name of the program you want to kill.

Knowing the program’s name, you can use the magnificent killall command and kill all processes in one single command killall program_name

Method 2: Kill a process using the top command

The top command is one of the popular commands, which is pre-installed on almost all Linux distributions. It is a powerful task management tool. To use it to kill a process, first open the top by entering:

This will open Top and list all the running processes:

top command

Inside the top command, press Shift+L. this will open a “Locate string” prompt, where we can search for the process by name. Once you have located the process that needs to be terminated, press the k key on the keyboard.

Now enter the process ID of the program.

Locate the process and kill using to command

This way, you can terminate any process using the top command. You can also use other system monitoring commands like htop for finding and terminating processes.

Method 3: Killing a process in Linux via GUI

If you are using a Linux desktop, you don’t necessarily have to use the terminal.

There is a task manager in every Linux distribution. It’s usually called a system monitor.

This system monitor is part of the desktop environment. GNOME, KDE, and Cinnamon, all of them have a system monitor. Just look for them in the system menu.

I’ll be demonstrating the GNOME system monitor here.

The default page lists all the running processes. You can kill a process by clicking on it and pressing the End Process button. Or you can right-click on the process and select Kill/End from the context menu.

Search and kill a process using GNOME system monitor

Also, you can note that the process tab lists the process ID of the respective program.

You may also use various third-party tools like Stacer.

What next?

If you are interested in learning more about this topic, I suggest getting familiar with various termination signals.

The ps command is also quite versatile. Learning its usage will be helpful as well.

So, you learned the command line and GUI methods of terminating a running process in Linux.

The command line method is evergreen and you can use it on any Linux distribution, desktop, or server.

Now it’s your turn. Do you prefer the command line method or the GUI tools?

Источник

Оцените статью
Adblock
detector