Index: /branches/eam_branches/ipp-20130509/Ohana/src/libohana/include/ohana.h
===================================================================
--- /branches/eam_branches/ipp-20130509/Ohana/src/libohana/include/ohana.h	(revision 35696)
+++ /branches/eam_branches/ipp-20130509/Ohana/src/libohana/include/ohana.h	(revision 35697)
@@ -283,4 +283,5 @@
 FILE   *fsetlockfile           PROTO((char *filename, double timeout, int type, int *state));
 int     fclearlockfile         PROTO((char *filename, FILE *f, int type, int *state));
+int     fchecklockfile         PROTO((char *filename, int type, int *state));
 
 /* in config.c */
Index: /branches/eam_branches/ipp-20130509/Ohana/src/libohana/src/glockfile.c
===================================================================
--- /branches/eam_branches/ipp-20130509/Ohana/src/libohana/src/glockfile.c	(revision 35696)
+++ /branches/eam_branches/ipp-20130509/Ohana/src/libohana/src/glockfile.c	(revision 35697)
@@ -1,3 +1,79 @@
 # include <ohana.h>
+
+int fchecklockfile (char *filename, int type, int *state) {
+  
+  int status;
+  char mode[3];
+  int fd;
+  FILE *f;
+  struct stat filestat;
+  struct flock filelock;
+
+  f = NULL;
+
+  /* define lock type */
+  filelock.l_start  = 0;
+  filelock.l_whence = SEEK_SET;
+  filelock.l_len    = 0;
+  filelock.l_pid    = 0;
+  switch (type) {
+  case LCK_HARD:
+  case LCK_XCLD:
+    filelock.l_type   = F_WRLCK;  /* set an exclusive lock */
+    strcpy (mode, "r+");
+    break;
+  case LCK_SOFT:
+    filelock.l_type   = F_RDLCK;  /* set a shared lock */
+    strcpy (mode, "r");
+    break;
+  default:
+    *state = LCK_INVALID;
+    goto failure;
+  }
+
+  /* check if file exists */
+  status = stat (filename, &filestat);
+  if ((status == -1) && (errno == ENOENT)) {
+    if (type == LCK_SOFT) {
+      *state = LCK_MISSING;
+      goto failure;
+    } 
+    /* otherwise, we need to be able to create file */ 
+    strcpy (mode, "w+");
+  }
+  
+  /* try to open file (create if it does not exist) */
+  f = fopen (filename, mode);
+  if (f == NULL) {
+    *state = LCK_ACCESS;
+    goto failure;
+  }
+  fd = fileno (f);
+
+  /* check the lock */
+  status = fcntl (fd, F_GETLK, &filelock);
+  if (status) {
+    *state = LCK_ACCESS;
+    goto failure;
+  }
+
+  if (filelock.l_pid) {
+    if (filelock.l_type == F_WRLCK) {
+      fprintf (stderr, "lock (hard) is held by pid %d\n", filelock.l_pid);
+    } else {
+      fprintf (stderr, "lock (soft) is held by pid %d\n", filelock.l_pid);
+    }
+  } else {
+    fprintf (stderr, "lock is NOT held\n");
+  }
+
+  fclose (f);
+  return TRUE;
+
+failure:
+  fprintf (stderr, "failed to check lock\n");
+  if (f        != NULL) fclose (f);
+  return FALSE;
+}
 
 FILE *fsetlockfile (char *filename, double timeout, int type, int *state) {
