Linux force close file

Forcefully Close a Program in Ubuntu

Sometimes ya gotta kill ’em all

When a program stops responding in Windows, most users know how to stop it by pressing Ctrl + Alt + Delete on their keyboard, pressing the Task Manager option and closing it from there. That approach doesn’t quite transfer to Linux distributions like Ubuntu, but that doesn’t mean that you’re short of options when a program crashes.

On the contrary—there are quite a few ways to close a program on Ubuntu using CMD. If you’re comfortable using the terminal, you can use commands like killall or xkill to force troublesome programs to close, or you can use the System Monitor app instead.

Using The System Monitor To Force Close a Running Ubuntu Process

While it’s easy enough to close an open process in Ubuntu using the terminal, beginners might not feel comfortable doing this. But an Ubuntu user doesn’t need to go near the terminal to force close a crashed program—you can use the System Monitor app instead.

The System Monitor works a lot like the Task Manager does for Windows PCs. It lists all the running processes on your PC, as well as giving you real-time information on your CPU, RAM, and disk usage. It also allows you to force close any crashed software that won’t respond or close directly.

  • To force close a program in Ubuntu using the System Monitor, press the Show Applications button at the bottom of the Ubuntu dock. In your Applications list, click on the System Monitor icon to launch it.

  • The System Monitor app will launch with the default Processes tab visible—if it doesn’t, click on the Processes tab at the top. In the processes list, find and locate the process (or processes) for your crashed program, right-click the entry, then press the Kill option. Alternatively, select the process and press the End Process button at the bottom of the System Monitor window.

  • System Monitor will ask for confirmation that you do want to end the running process. To confirm, press the Kill Process button.

If it was successful, the process should disappear from your System Monitor processes list. If the program had an open window, this window should also close at this point.

If System Monitor didn’t successfully close the program, you’ll need to try using the terminal instead.

How To Close An Open Window Using The xkill Command

In most cases, the System Monitor software will forcefully close a program on Ubuntu. If it doesn’t, then you’ll need to switch to the terminal to close any non-responding programs.

Thankfully, there’s an easy-to-use command called xkill that will allow you to forcefully close any program with an open window.

  • Most modern versions of Ubuntu should come with the xkill package installed but, if you find it isn’t installed, you’ll need to install xkill first before you can use it. Open a terminal and type sudo apt install xorg-xkill to do this. Once it’s installed, simply type xkill or sudo xkill to begin using it.
Читайте также:  Центре обновления windows не может быть запущен

  • The terminal output will tell you to select the window whose client you wish to kill with button 1. In other words, use your mouse to click on an open window—xkill will close this for you. Once killed, the terminal output will respond with a killing creator message before ending.

This will only work for programs that are visibly not responding, including any programs with a GUI window that you can interact with.

Forcefully Closing a Program on Ubuntu Using pkill, kill Or killall Commands

Using xkill requires you to be using Ubuntu with a GUI. If you’re running a headless version of Ubuntu without a GUI installed, such as Ubuntu Server, then you’ll need to use the pkill, kill or killall commands instead.

The kill and pkill commands will terminate any single process running on your PC, while killall will kill all related processes. Some programs (such as Google Chrome) use multiple system processes, so using kill or pkill may not necessarily end them if the program stops responding.

  • To use kill, you’ll need to know the process id number (PID) assigned to it—open a terminal and type top to view a list of currently running processes. You’ll find the process id number under the PID column and the name of the process/program under the Command column.

  • To stop a terminal using kill, type kill pid, replacing pid with your process id (for instance, kill 582). If it doesn’t work, type sudo kill pid instead. A successful process termination shouldn’t result in any extra terminal output, but you can type top again to double-check.

  • The pkill command doesn’t require a process id number, but it does require the package name. You can check this using top first under the Command column. Once you’re ready, type pkill process, replacing process with the package name (or sudo pkill process if the process won’t terminate). As with kill, a successful pkill command will return no messages or output.

  • If a program has multiple processes, you can use the killall command to terminate them all at once. Like pkill, this uses the package name—use top to find this under the Command column. To use killall, type killall process or sudo killall process, replacing process with the package name. Like pkill, no messages will be returned at the terminal if the command is a success.

Effective Ubuntu Maintenance

Even when running software stops responding, Ubuntu gives you the tools to stay in control. Now you know how to close a process in Ubuntu using the terminal, you can take advantage of other cool Linux terminal commands to backup your PC, pause running commands rather than ending them, and more.

A crashing program should be a rare occurrence, but if it’s happening more often than it should, it could point to a problem with your Ubuntu installation. You’ll need to look into some of the common reasons for Ubuntu crashes to (hopefully) resolve your issues.

Ben Stockton is a freelance technology writer based in the United Kingdom. In a past life, Ben was a college lecturer in the UK, training teens and adults. Since leaving the classroom, Ben has taken his teaching experience and applied it to writing tech how-to guides and tutorials, specialising in Linux, Windows, and Android. He has a degree in History and a postgraduate qualification in Computing. Read Ben’s Full Bio

Читайте также:  Нативные windows приложения это

Источник

close(3) — Linux man page

Prolog

Synopsis

Description

The close() function shall deallocate the file descriptor indicated by fildes. To deallocate means to make the file descriptor available for return by subsequent calls to open() or other functions that allocate file descriptors. All outstanding record locks owned by the process on the file associated with the file descriptor shall be removed (that is, unlocked).

If close() is interrupted by a signal that is to be caught, it shall return -1 with errno set to [EINTR] and the state of fildes is unspecified. If an I/O error occurred while reading from or writing to the file system during close(), it may return -1 with errno set to [EIO]; if this error is returned, the state of fildes is unspecified.

When all file descriptors associated with a pipe or FIFO special file are closed, any data remaining in the pipe or FIFO shall be discarded.

When all file descriptors associated with an open file description have been closed, the open file description shall be freed.

If the link count of the file is 0, when all file descriptors associated with the file are closed, the space occupied by the file shall be freed and the file shall no longer be accessible.

If a STREAMS-based fildes is closed and the calling process was previously registered to receive a SIGPOLL signal for events associated with that STREAM, the calling process shall be unregistered for events associated with the STREAM. The last close() for a STREAM shall cause the STREAM associated with fildes to be dismantled. If O_NONBLOCK is not set and there have been no signals posted for the STREAM, and if there is data on the module’s write queue, close() shall wait for an unspecified time (for each module and driver) for any output to drain before dismantling the STREAM. The time delay can be changed via an I_SETCLTIME ioctl() request. If the O_NONBLOCK flag is set, or if there are any pending signals, close() shall not wait for output to drain, and shall dismantle the STREAM immediately.

If the implementation supports STREAMS-based pipes, and fildes is associated with one end of a pipe, the last close() shall cause a hangup to occur on the other end of the pipe. In addition, if the other end of the pipe has been named by fattach(), then the last close() shall force the named end to be detached by fdetach(). If the named end has no open file descriptors associated with it and gets detached, the STREAM associated with that end shall also be dismantled.

If fildes refers to the master side of a pseudo-terminal, and this is the last close, a SIGHUP signal shall be sent to the controlling process, if any, for which the slave side of the pseudo-terminal is the controlling terminal. It is unspecified whether closing the master side of the pseudo-terminal flushes all queued input and output.

Читайте также:  После установки windows 10 не загружается экран

If fildes refers to the slave side of a STREAMS-based pseudo-terminal, a zero-length message may be sent to the master.

When there is an outstanding cancelable asynchronous I/O operation against fildes when close() is called, that I/O operation may be canceled. An I/O operation that is not canceled completes as if the close() operation had not yet occurred. All operations that are not canceled shall complete as if the close() blocked until the operations completed. The close() operation itself need not block awaiting such I/O completion. Whether any I/O operation is canceled, and which I/O operation may be canceled upon close(), is implementation-defined.

If a shared memory object or a memory mapped file remains referenced at the last close (that is, a process has it mapped), then the entire contents of the memory object shall persist until the memory object becomes unreferenced. If this is the last close of a shared memory object or a memory mapped file and the close results in the memory object becoming unreferenced, and the memory object has been unlinked, then the memory object shall be removed.

If fildes refers to a socket, close() shall cause the socket to be destroyed. If the socket is in connection-mode, and the SO_LINGER option is set for the socket with non-zero linger time, and the socket has untransmitted data, then close() shall block for up to the current linger interval until all data is transmitted.

Return Value

Upon successful completion, 0 shall be returned; otherwise, -1 shall be returned and errno set to indicate the error.

Errors

The close() function shall fail if: EBADF The fildes argument is not a valid file descriptor. EINTR The close() function was interrupted by a signal.

The close() function may fail if: EIO An I/O error occurred while reading from or writing to the file system.

The following sections are informative.

Examples

Reassigning a File Descriptor

The following example closes the file descriptor associated with standard output for the current process, re-assigns standard output to a new file descriptor, and closes the original file descriptor to clean up. This example assumes that the file descriptor 0 (which is the descriptor for standard input) is not closed.

Incidentally, this is exactly what could be achieved using:

Closing a File Descriptor

In the following example, close() is used to close a file descriptor after an unsuccessful attempt is made to associate that file descriptor with a stream.

Application Usage

An application that had used the stdio routine fopen() to open a file should use the corresponding fclose() routine rather than close(). Once a file is closed, the file descriptor no longer exists, since the integer corresponding to it no longer refers to a file.

Rationale

The use of interruptible device close routines should be discouraged to avoid problems with the implicit closes of file descriptors by exec and exit(). This volume of IEEE Std 1003.1-2001 only intends to permit such behavior by specifying the [EINTR] error condition.

Future Directions

See Also

STREAMS, fattach(), fclose(), fdetach(), fopen(), ioctl(), open(), the Base Definitions volume of IEEE Std 1003.1-2001,

Источник

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