diff -Naur motion-3.2.6-orig/conf.c motion-3.2.6/conf.c
--- motion-3.2.6-orig/conf.c	Wed Mar 22 23:17:45 2006
+++ motion-3.2.6/conf.c	Fri Jul  7 05:29:31 2006
@@ -134,6 +134,7 @@
 	text_double:           0,
 	despeckle:             NULL,
 	minimum_motion_frames: 1,
+	pid_file:             NULL,
 	// debug_parameter:       0
 };
 
@@ -1157,6 +1158,13 @@
 	copy_string,
 	print_string
 	},
+	{
+	"pid_file",
+	"# File to store the process ID",
+	CONF_OFFSET(pid_file),
+	copy_string,
+	print_string
+	},
 /*
 	{
 	"debug_parameter",
@@ -1197,13 +1205,16 @@
 	 * if necessary. This is accomplished by calling mystrcpy();
 	 * see this function for more information.
 	 */
-	while ((c=getopt(conf->argc, conf->argv, "c:d:hns?"))!=EOF)
+	while ((c=getopt(conf->argc, conf->argv, "c:d:hns?p:"))!=EOF)
 		switch (c) {
 			case 'c':
 				if (thread==-1) strcpy(cnt->conf_filename, optarg);
 				break;
 			case 'n':
 				cnt->daemon=0;
+				break;
+			case 'p':
+				cnt->conf.pid_file = mystrcpy(cnt->conf.pid_file, optarg);
 				break;
 			case 's':
 				conf->setup_mode=1;
diff -Naur motion-3.2.6-orig/conf.h motion-3.2.6/conf.h
--- motion-3.2.6-orig/conf.h	Wed Mar 22 23:17:45 2006
+++ motion-3.2.6/conf.h	Fri Jul  7 05:29:31 2006
@@ -118,6 +118,7 @@
 	int text_double;
 	const char *despeckle;
 	int minimum_motion_frames;
+	char *pid_file;
 	// int debug_parameter;
 	int argc;
 	char **argv;
diff -Naur motion-3.2.6-orig/motion.c motion-3.2.6/motion.c
--- motion-3.2.6-orig/motion.c	Wed Mar 22 23:17:45 2006
+++ motion-3.2.6/motion.c	Fri Jul  7 05:38:41 2006
@@ -1541,6 +1541,7 @@
 {
 	int i;
 	struct sigaction sig_ign_action;
+	FILE *pidf;
 	
 	/* Setup sig_ign_action */
 #ifdef SA_RESTART
@@ -1553,9 +1554,15 @@
 
 	if (fork()) {
 		motion_log(-1, 0, "Motion going to daemon mode");
-		exit(0);
+  		exit(0);
+  	}
+
+	if ( cnt_list[0]->conf.pid_file
+	    && ( pidf = fopen(cnt_list[0]->conf.pid_file, "w+")) ) {
+	    (void) fprintf(pidf, "%d\n", getpid());
+	    fclose(pidf);
 	}
-		
+
 	/* changing dir to root enables people to unmount a disk
 	   without having to stop Motion */
 	if (chdir("/")) {
