I want to use create a file in a known place when application starts so I can know how many instance of the application is running by doing the following:
void Init(int id)
sprintf(buf, "/tmp/process_%d.cnt", getpid());
int flags = O_CREAT|O_WRONLY;
int mode = S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH;
mode_t m = umask(0);
m_h = open( buf, flags, mode );
However, as soon as I unlink() the file, the file disappeared from the file system. Is there any way I can make sure the file gets deleted should the process terminates but visible during the life time of the process?