Index: /trunk/ll_drmaa/session.c
===================================================================
--- /trunk/ll_drmaa/session.c	(revision 20)
+++ /trunk/ll_drmaa/session.c	(revision 26)
@@ -132,5 +132,5 @@
 	LL_job job_info;
 
-	char *monitor_program = LL_DRMAA_BIN_DIR"/monitor";
+	char *monitor_program = LL_DRMAA_BIN_DIR"/lldrmaa_monitor";
 
 	TRY
@@ -147,8 +147,17 @@
 
 		connection_lock = fsd_mutex_lock( &self->drm_connection_mutex );
-		status = llsubmit(cmd_path, monitor_program, llself->unix_socket_name, &job_info, LL_JOB_VERSION);
+		if (self->wait_thread_run_flag) 
+		  {
+			fsd_log_info(("llsubmit(%s, %s, %s, %p, %d)",cmd_path, monitor_program, llself->unix_socket_name, (void*)&job_info, LL_JOB_VERSION));
+			status = llsubmit(cmd_path, monitor_program, llself->unix_socket_name, &job_info, LL_JOB_VERSION);
+		  }
+		else
+		  {
+			fsd_log_info(("llsubmit(%s, NULL, NULL, %p, %d)",cmd_path, (void*)&job_info, LL_JOB_VERSION));
+			status = llsubmit(cmd_path, NULL, NULL, &job_info, LL_JOB_VERSION);
+		  }
 		connection_lock = fsd_mutex_unlock( &self->drm_connection_mutex );
 
-		if(remove(cmd_path) == -1)
+		if(getenv("LLDRMAA_KEEP_CMD") == NULL && remove(cmd_path) == -1)
 			fsd_log_warning(("Can't delete cmd file: %s", cmd_path));
 
@@ -161,5 +170,7 @@
 		 }
 		else /* 0 */
+		 {
 			fsd_log_debug(("llsubmit: %s",lldrmaa_err_submit(status)));
+		 }
 
 		if( start != end )
@@ -170,5 +181,5 @@
 			 {
 			 	job_ids[i] = fsd_asprintf("%s.%d.%d", job_info.step_list[i]->id.from_host, job_info.step_list[i]->id.cluster, job_info.step_list[i]->id.proc);
-
+				fsd_log_info((" new array job id: %s", job_ids[i]));
 				job = lldrmaa_job_new( fsd_strdup(job_ids[i]) );
 				job->session = self;
@@ -185,4 +196,5 @@
 			job_ids[0] = fsd_asprintf( "%s.%d.0", job_info.step_list[0]->id.from_host, job_info.step_list[0]->id.cluster);
 
+			fsd_log_info((" new job id: %s", job_ids[0]));
 			job = lldrmaa_job_new( fsd_strdup(job_ids[0]) );
 			job->session = self;
@@ -247,6 +259,4 @@
 	 }
 
-	if ( !self->wait_thread_started )
-		fsd_exc_raise_msg(FSD_ERRNO_INTERNAL_ERROR, "DRMAA for LL requires that wait thread is enable. Don't disable it in configuration file!" );
 }
 
Index: /trunk/ll_drmaa/drmaa.c
===================================================================
--- /trunk/ll_drmaa/drmaa.c	(revision 20)
+++ /trunk/ll_drmaa/drmaa.c	(revision 26)
@@ -17,5 +17,4 @@
  */
 
-#include <sys/timers.h>
 #include <sys/time.h>
 #include <sys/wait.h>
Index: /trunk/ll_drmaa/Makefile.am
===================================================================
--- /trunk/ll_drmaa/Makefile.am	(revision 20)
+++ /trunk/ll_drmaa/Makefile.am	(revision 26)
@@ -33,9 +33,9 @@
 libdrmaa_la_LDFLAGS = @LL_LDFLAGS@ -version-info @LL_DRMAA_VERSION_INFO@
 
-bin_PROGRAMS = monitor
+bin_PROGRAMS = lldrmaa_monitor
 
-monitor_SOURCES = monitor.c
+lldrmaa_monitor_SOURCES = monitor.c
 
-monitor_CPPFLAGS = -I$(top_srcdir)/drmaa_utils
+lldrmaa_monitor_CPPFLAGS = -I$(top_srcdir)/drmaa_utils
 
 dist_sysconf_DATA = ll_drmaa.conf.example
Index: /trunk/ll_drmaa/job.c
===================================================================
--- /trunk/ll_drmaa/job.c	(revision 20)
+++ /trunk/ll_drmaa/job.c	(revision 26)
@@ -35,4 +35,6 @@
 
 #include <llapi.h>
+
+#define LL_DRMAA_MAX_MISSING_TIME (60)
 
 static void
@@ -287,8 +289,35 @@
 		}
 
-		data = ll_get_objs(job, LL_SCHEDD, NULL, &obj_count, &err_code);
+		data = ll_get_objs(job, LL_CM, NULL, &obj_count, &err_code);
 		if (data == NULL) {
-			fsd_log_debug(("Code: %d ll_get_objs() returns NULL. %s",lldrmaa_map_get_objs(err_code), lldrmaa_err_get_objs(err_code) ));
-			/* This error means that there is no info in LL_SCHEDD but this job have probably ended and will be detected by wait_thread. This won't be fsd_log_warning because displays too often during program execution */
+			if (err_code == LL_GET_OBJS_NO_OBJECTS_ERR)
+			  {
+				if (self->state != DRMAA_PS_UNDETERMINED) 
+				  {
+					fsd_log_info(("Job %s missing. Assuming finished", self->job_id));
+					self->state = DRMAA_PS_DONE;
+					self->exit_status = 0;
+				  }
+				else if (llself->missing_time == 0)
+				 {
+					llself->missing_time = time(NULL);
+					fsd_log_debug(("Job %s missing for the first time", self->job_id)); /* Job may not yet be visible in LL */
+				 }
+				else if (time(NULL) - llself->missing_time > LL_DRMAA_MAX_MISSING_TIME)
+				 {
+					fsd_log_error(("Job %s missing for more then %d seconds. Assuming failef", self->job_id, LL_DRMAA_MAX_MISSING_TIME)); 
+					/* Job may not yet be visible in LL */
+					self->state = DRMAA_PS_FAILED;
+					self->exit_status = -1;
+				 }
+				else
+				 {
+					fsd_log_debug(("Job %s still missing", self->job_id));
+				 }
+			  }
+			else
+			  {
+				fsd_log_error(("Code: %d,%d ll_get_objs() returns NULL. %s", err_code, lldrmaa_map_get_objs(err_code), lldrmaa_err_get_objs(err_code) ));
+			  }
 		} else {
 
@@ -312,7 +341,7 @@
 			}
 
-			llself->read_job_info( self, step_state, hold_type);
-
-			fsd_log_info(("LL State: %d -> DRMAA: %s",step_state,drmaa_job_ps_to_str(self->state)));
+			llself->read_job_info(self, step_state, hold_type);
+
+			fsd_log_info(("LL State: %d -> DRMAA: %s", step_state, drmaa_job_ps_to_str(self->state)));
 		}
 	}
@@ -352,4 +381,5 @@
 	self->super.control = lldrmaa_job_control;
 	self->super.update_status = lldrmaa_job_update_status;
+	self->missing_time = 0;
 	self->read_job_info_mon = lldrmaa_job_read_job_info_mon;
 	self->read_job_info = lldrmaa_job_read_job_info;
@@ -471,49 +501,4 @@
 	 	}
 
-		TRY
-		{
-			const char *command = NULL;
-			char *command_expanded = NULL;
-			const char *const *i;
-			int j;
-
-			/* remote command */
-			command = jt->get_attr( jt, DRMAA_REMOTE_COMMAND );
-			if( command == NULL )
-				fsd_exc_raise_msg(
-						FSD_DRMAA_ERRNO_CONFLICTING_ATTRIBUTE_VALUES,
-						"drmaa_remote_command not set for job template"
-						);
-
-			command_expanded = expand->expand( expand, fsd_strdup(command), FSD_DRMAA_PH_HD | FSD_DRMAA_PH_WD );
-
-			fprintf(fd,"# @ executable = %s\n", command_expanded);
-			fsd_log_debug(("# @ executable = %s\n", command_expanded));
-
-			fsd_free(command_expanded);
-
-			/* arguments list */
-			vector = jt->get_v_attr( jt, DRMAA_V_ARGV );
-
-			if( vector )
-		 	{
-				fprintf(fd,"# @ arguments =");
-				fsd_log_debug(("# @ arguments ="));
-
-				for( i = vector, j = 2;  *i;  i++, j++ )
-				{
-					char *arg_expanded = expand->expand( expand, fsd_strdup(*i), FSD_DRMAA_PH_HD | FSD_DRMAA_PH_WD );
-
-					fprintf(fd," '%s'", arg_expanded);
-					fsd_log_debug(("%s", arg_expanded));
-
-					fsd_free(arg_expanded);
-				}
-			}
-
-			fprintf(fd," \n");
-		}
-		END_TRY
-
 		/* start time */
 		value = jt->get_attr( jt, DRMAA_START_TIME );
@@ -779,4 +764,54 @@
 				fprintf(fd,"# @ queue\n");
 				fsd_log_debug(("# @ queue"));
+				
+				fprintf(fd,"\n");
+				fprintf(fd,"echo >&2\n"); /* this line forces creation of stderr file */
+
+				TRY
+				{
+					const char *command = NULL;
+					char *command_expanded = NULL;
+					const char *const *i;
+					int j;
+
+					/* remote command */
+					command = jt->get_attr( jt, DRMAA_REMOTE_COMMAND );
+					if( command == NULL )
+						fsd_exc_raise_msg(
+								FSD_DRMAA_ERRNO_CONFLICTING_ATTRIBUTE_VALUES,
+								"drmaa_remote_command not set for job template"
+								);
+
+					command_expanded = expand->expand( expand, fsd_strdup(command), FSD_DRMAA_PH_HD | FSD_DRMAA_PH_WD );
+
+					fprintf(fd,"%s", command_expanded); /* we put the commmand at the end of script (instead of using @executable keyword
+										 in roder to avoid coping of the binary */
+					fsd_log_debug(("command = %s\n", command_expanded));
+
+					fsd_free(command_expanded);
+
+					/* arguments list */
+					vector = jt->get_v_attr( jt, DRMAA_V_ARGV );
+
+					if( vector )
+					{
+						fsd_log_debug(("arguments = "));
+
+						for( i = vector, j = 2;  *i;  i++, j++ )
+						{
+							char *arg_expanded = expand->expand( expand, fsd_strdup(*i), FSD_DRMAA_PH_HD | FSD_DRMAA_PH_WD );
+
+							fprintf(fd," '%s'", arg_expanded);
+							fsd_log_debug(("%s", arg_expanded));
+
+							fsd_free(arg_expanded);
+						}
+					}
+
+					fprintf(fd," \n");
+				}
+				END_TRY
+
+
 			}
 		}
Index: /trunk/ll_drmaa/job.h
===================================================================
--- /trunk/ll_drmaa/job.h	(revision 20)
+++ /trunk/ll_drmaa/job.h	(revision 26)
@@ -36,4 +36,5 @@
 struct lldrmaa_job_s {
 	fsd_job_t super;
+	time_t missing_time;
 
 	void (*read_job_info_mon)( fsd_job_t *self, const char * state , unsigned status);
Index: /trunk/m4/ax_ll.m4
===================================================================
--- /trunk/m4/ax_ll.m4	(revision 20)
+++ /trunk/m4/ax_ll.m4	(revision 26)
@@ -45,9 +45,10 @@
 	LL_INCLUDES="-I${with_ll_inc}"
 else
-	LLSUBMIT_PATH=`which llsubmit`
+	LLSUBMIT_PATH=`readlink -f $(which llsubmit)`
 	if test x"$LLSUBMIT_PATH" != x; then
 		LLSUBMIT_DIR=`dirname $LLSUBMIT_PATH`
 		LL_HOME=`dirname $LLSUBMIT_DIR`
 		LL_INCLUDES="-I$LL_HOME/include"
+		AC_MSG_NOTICE([no --with-ll-inc given. Using llsubmit path based guess: $LL_INCLUDES])
 	else
 		ax_ll_msg="no llsubmit in PATH"
@@ -61,5 +62,5 @@
 if test x$with_ll_lib == x; then
 	
-	LLSUBMIT_PATH=`which llsubmit`
+	LLSUBMIT_PATH=`readlink -f $(which llsubmit)`
 	
 	if test x"$LLSUBMIT_PATH" != x; then
@@ -67,4 +68,5 @@
 		LL_HOME=`dirname $LLSUBMIT_DIR`
 		with_ll_lib=$LL_HOME/lib
+		AC_MSG_NOTICE([no --with-ll-lib given. Using llsubmit path based guess: $with_ll_lib])
 	else
 		ax_ll_msg="no llsubmit in PATH"
