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?
"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.
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.
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.