Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to end a process or abort a program in a Linux system

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article is about how to end a process or abort a program in a Linux system. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

There are several ways to terminate a program in Linux using the command line or graphical interface.

When a process goes wrong, you may want to abort or kill the process. In this article, we will explore terminating a process or application in a command line and graphical interface, where we use gedit as a sample program.

Use the command line or character terminal interface Ctrl + C

One problem with invoking the gedit program from the command line (if you don't use the gedit & command) is that the shell session is blocked and cannot release the command line prompt. In this case, Ctrl + C (the key combination of Ctrl and C) works well. This will terminate the gedit and all work will be lost (unless the file has been saved). Ctrl + C sends a SIGINT signal to gedit. This is a stop signal that terminates the process by default, which instructs shell to stop running gedit and return to the loop of the main function, and you will return to the prompt.

$gedit ^ CCtrl + Z

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

The following command will stop (kill / interrupt) gedit and return to the shell prompt.

$gedit ^ Z [1] + Stopped gedit$

Once the process is suspended (in the case of gedit), nothing can be written or done in gedit. In the background, the process becomes a job that can be verified using the jsbs command.

$jobs [1] + Stopped gedit

Jobs allows you to control multiple processes in a single shell session. You can terminate, resume the job, or move the job to the foreground or background as needed.

Let's restore gedit in the background and release the prompt to run other commands. You can do this with the bg command, followed by the job ID (note the [1] shown by the jobs command above, which is the job ID).

$bg 1 [1] + gedit &

This is similar to using gedit directly to start the program:

$gedit & using kill

The kill command provides precise control of the signal, allowing you to send a signal for the process by specifying the signal name or signal number, followed by the process ID or PID.

One thing I like about the kill command is that it can also control the process according to the job ID. Let's use the gedit & command to start the gedit service in the background. Suppose I get a job ID for gedit through the jobs command, let's send a SIGINT signal for gedit:

$kill-s SIGINT 1

The job ID needs to be prefixed with%, otherwise kill will treat it as PID.

Without explicitly specifying the signal, the kill still works. At this point, a SIGTERM signal that interrupts the process is sent by default. Execute kill-l to view a list of signal names and use the man kill command to read the manual.

Use killall

If you don't want to use a specific working ID or PID,killall, you can use a specific process name. The easiest way to use killall to interrupt gedit is:

$killall gedit

It terminates all processes named gedit. Similar to kill, the default signal sent is SIGTERM. Use the-I option to ignore the case of the process name.

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

Check the manual to learn more killall command options (such as-u).

Use xkill

Have you ever encountered a player crash, such as VLC gray screen or hang? Now you can get the PID of the process as above to kill it, or use the xkill command to terminate the application.

Using xkill

Xkill allows you to close the window using the mouse. Just execute the xkill command on the terminal, and it will change the mouse cursor to an X or a small skeleton icon. Click x on the process window you want to close. Use xkill carefully, as described in the manual is consistent, it is dangerous. I already warned you!

Thank you for reading! This is the end of the article on "how to end the process or stop the program in the Linux system". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report