xref: /XiangShan/scripts/utils/lock-emu.c (revision ba6bb9d6ea202b65d5546b84af3d7992e6eccbe6)
1 #include<unistd.h>
2 #include<stdio.h>
3 #include<stdlib.h>
4 #include<sys/stat.h>
5 #include<fcntl.h>
6 
7 int tryLock(char * file){
8     return open(file, O_CREAT | O_EXCL);
9 }
10 
11 int main(int argc, char* argv[]){
12     int fd;
13 	if(argc < 2){
14 	    printf("arguments are not right!\n");
15 		exit(-1);
16 	}
17 
18     do{
19         fd = tryLock(argv[1]);
20         if(fd > 0) break;
21 		printf("there is a job running, waiting ...\n");
22 		sleep(10);
23 	} while(1);
24 
25     return 0;
26 }
27 
28