Wills
In an ideal world, an operating system would provide cleanup hooks for anything that might be left in a bad state by the sudden death or prolonged hang of a process or thread, at least if programmatically cleaning it up from userspace is impossible or takes a lot of extra work.
Two examples off the top of my head are command line terminals being left with input echoing disabled and temporary files being left abandoned on the file system because a process died or froze due to an uncatchable signal or other problems.
We could call this idea "wills". It is like the process leaving behind a will. Registering it with a robust and trusted party. It goes into effect after the process dies. The process can revoke it while still alive if it no longer needs it.
Installing and revoking these wills should be atomic with the resource mutation that warrants it. The will to reset terminal settings should be registerable in the same system call that sets them, and revocable in the system call that unsets them. The will to delete a file should be registerable in the same system call that creates it, and revocable in the will that deletes it.
There is even an analogue here to "living wills". A robust system needs a good policy for what to do with processes that stop doing what they are supposed to be doing. Allow wills to kill the registering process. Allow wills to activate on conditions like "if write(2) is not called on this file descriptor every [time interval]", or "if this process does not do anything at all within [timeout]".
Like a dead man switch or watchdog, but one crafted by the process itself based on its intimate knowledge of what it is supposed to be doing.
This of course would be much easier to implement if there was some way to bundle system calls together, to represent a system call and its arguments as data in memory. Could share that implementation with batching system calls.










