mesh_driver/lunix-attach.c
static int tty_already_locked(char *nam)
{
	int  i = 0, pid = 0;
	FILE *fd = 0;

	/* Does the lock file on our device exist? */
	if ((fd = fopen(nam, "r")) == NULL)
		return 0; /* No, return perm to continue */
  
	/*
	 * Yes, the lock is there.  Now let's make sure 
	 * at least there's no active process that owns
	 * that lock.
	 */
	i = fscanf(fd, "%d", &pid);
	(void) fclose(fd);
 
	if (i != 1) /* Lock file format's wrong! Kill't */
		return 0;

	/* We got the pid, check if the process's alive */
	if (kill(pid, 0) == 0)      /* it found process */
		return 1;          /* Yup, it's running... */

	/* Dead, we can proceed with locking this device...  */
	return 0;
}
/* Check for an existing lock file on our device */
Check for an existing lock file on our device
Check for an existing lock file on our device
static int tty_already_locked(char *nam)
{
	int  i = 0, pid = 0;
	FILE *fd = 0;
	if ((fd = fopen(nam, "r")) == NULL)
		return 0; 
	i = fscanf(fd, "%d", &pid);
	(void) fclose(fd);
	if (i != 1) 
		return 0;
	if (kill(pid, 0) == 0)      
		return 1;          
	return 0;
}
static int tty_already_locked ( char * nam ) { int i = 0 , pid = 0 ; FILE * fd = 0 ; if ( ( fd = fopen ( nam , " " ) ) == NULL ) return 0 ; i = fscanf ( fd , " " , & pid ) ; ( void ) fclose ( fd ) ; if ( i != 1 ) return 0 ; if ( kill ( pid , 0 ) == 0 ) return 1 ; return 0 ; }
Check for an existing lock file on our device
Check for an existing lock file on our device
/* Does the lock file on our device exist? */ /* No, return perm to continue */ /*
	 * Yes, the lock is there.  Now let's make sure 
	 * at least there's no active process that owns
	 * that lock.
	 */ /* Lock file format's wrong! Kill't */ /* We got the pid, check if the process's alive */ /* it found process */ /* Yup, it's running... */ /* Dead, we can proceed with locking this device...  */