๐Ÿš€ go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: es.comp.os.linux.programacion
2 messages
2 total messages Started by Colin Mahoney Wed, 01 Sep 1999 00:00
Lock files
#18539
Author: Colin Mahoney
Date: Wed, 01 Sep 1999 00:00
7 lines
725 bytes
I want to create a lock file while I open a file, process it, write
out the new file then overwrite the old one with the new one.

What's the standard way to do this? I have no previous experience with
linux, so thanks for any help.

Colin Mahoney
Re: Lock files
#18470
Author: *puntero_loco
Date: Thu, 02 Sep 1999 00:00
36 lines
1798 bytes
El Wed, 01 Sep 1999 16:37:45 GMT, Colin Mahoney <cmahoney@readysoft.es> escribi๏ฟฝ:
|I want to create a lock file while I open a file, process it, write
|out the new file then overwrite the old one with the new one.
|
|What's the standard way to do this? I have no previous experience with
|linux, so thanks for any help.
|
|Colin Mahoney

#include <stdio.h>
#include <unistd.h>

int main(){

status = fopen("/tmp/.lock","r"); 
if (status != NULL) // Check if lockfile already exist
    {
	fprintf(stderr,"Lock file already exist in /tmp/.lock\n");
	fclose(status);
	exit(1);
}
lock = fopen("/tmp/.lock","w"); // lockfile don't exist, create one
[HERE YOU OPEN YOUR FILE, PROCESS IT
, WRITE, ETC]
fclose(lock);
ulink("/tmp/.lock"); // Delete the lockfile 

}

For more references write on the shell "info libc" (without the quotes).
-- 
 /-----------------------------\
|      *puntero_loco            |  
|     Debian 2.1 Slink          |
|  jajsNOSPAM@retemail.es       |
| http://personal5.iddeo.es/jajs|
 \-----------------------------/
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads