2

I want to kill a process which has an open connection to a database. If I kill the process, can I make sure that the database is unlocked?

  • Without knowing the database one can say nothing definite about it, as there are many different approaches of locking. – Jaleks Jan 2 '17 at 22:41
7

"All of the file descriptors, directory streams, conversion descriptors, and message catalog descriptors open in the calling process shall be closed". That's what POSIX says should happen if a process is exiting due to a signal (i.e. by "killing it").

So a client, a process accessing a server, would definitely close its end of a network connection. The behaviour of a server ("database") when a client ("your process") is killed is up to the server to decide (detect, and act upon).

The network connection will definitely be closed on the client side, but what the server does with the session in this case is hard to say. If it has a lock on a table or row in a table, when should it be released?

MySQL has an idle session timeout after which it releases the locks held by a disappearing client (see this StackOverflow question). You will have to look in the documentation for the particular database that you use to see what might happen, but my guess is that there would be some form of idle timer involved in most cases.

  • 2
    +1 In one extreme case I encountered, killing a DB client that had wedged a very long large transaction caused a huge rollback that locked out all useful access to the DB for over 12 hours. – dave_thompson_085 Jan 3 '17 at 7:12
1

yes but...

Killing a process closes its files, but it's not unusual for a kill on a process connected via a socket or other network connection (used with databases for instance) to not succeed in immediately killing the process. You'll see a process waiting to close using ps, for instance.

  • That doesn't seem accurate... You'll see a connection waiting to close using netstat, but you'll not see a zombie using ps. Not on account of an unclosed socket, anyway. – Celada Jan 2 '17 at 21:53
0

Usually,it will kill all file opened by this process. However,when some file descriptors is used somewhere, it will not be closed for sure.

  • I'm unsure of what you mean by "kill all files" and also what you mean by the second sentence. – Kusalananda Nov 23 '18 at 13:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.