How to create a file only if it doesn't exist?

前端 未结 5 1307
庸人自扰
庸人自扰 2021-01-12 04:10

I wrote a UNIX daemon (targeting Debian, but it shouldn\'t matter) and I wanted to provide some way of creating a \".pid\" file, (a file which contains the process identifie

5条回答
  •  感动是毒
    2021-01-12 04:28

    The only way I can think of is to use system level locks. See this: C++ how to check if file is in use - multi-threaded multi-process system

提交回复
热议问题