Does a process know whether a system resource is u

2019-06-01 04:07发布

问题:

The question comes from: RAII and system resource cleanup

Actually cleanup system resource is hard. In my mind, a process can't "know" whether a system resource(file, message queue, semaphore, shared memory) is used by other process or not. If it's true, how to guarantee to cleanup system resource safely?

If that is no a reliable way to do that, how can we do? Are there some common ways for it?