diff --git a/src/feh.h b/src/feh.h
index 457265274761b650d5a6d633efad8e35fc9cff6b..fb9fefe464f69427e16881b7d73ed92aa07adc54 100644
--- a/src/feh.h
+++ b/src/feh.h
@@ -201,4 +201,6 @@ extern char *mode;		/* label for the current mode */
 /* to terminate long-running children with SIGALRM */
 extern int childpid;
 
+extern int control_via_stdin;
+
 #endif
diff --git a/src/keyevents.c b/src/keyevents.c
index b5c1949c1aa13e699af3e777151448bb08d88337..2e496765c40d992abd5b3faacccdcbf4508dd20b 100644
--- a/src/keyevents.c
+++ b/src/keyevents.c
@@ -271,7 +271,8 @@ void feh_event_handle_stdin()
 	char stdin_buf[2];
 	KeySym keysym = NoSymbol;
 	if (read(STDIN_FILENO, &stdin_buf, 1) == -1) {
-		weprintf("reading a command from stdin failed");
+		if (control_via_stdin)
+			weprintf("reading a command from stdin failed");
 		return;
 	}
 	stdin_buf[1] = '\0';
diff --git a/src/main.c b/src/main.c
index b3f121cbcf8801819bfd23d6a60c577b2a43b3f2..cb2964fa6d0b979cf3adf089c9903d5dae0cb015 100644
--- a/src/main.c
+++ b/src/main.c
@@ -234,7 +234,7 @@ void feh_clean_exit(void)
 	if(disp)
 		XCloseDisplay(disp);
 
-	if (control_via_stdin)
+	if (control_via_stdin && isatty(STDIN_FILENO))
 		if (tcsetattr(STDIN_FILENO, TCSANOW, &old_term_settings) == -1)
 			eprintf("tcsetattr failed");
 
diff --git a/src/signals.c b/src/signals.c
index 0b18aac8658615026b8a6e32c465894f38c10063..8a3a8f72c53729e84f7fec90668c577a334cb0bd 100644
--- a/src/signals.c
+++ b/src/signals.c
@@ -40,7 +40,8 @@ void setup_signal_handlers()
 		(sigaddset(&feh_ss, SIGALRM) == -1) ||
 		(sigaddset(&feh_ss, SIGTERM) == -1) ||
 		(sigaddset(&feh_ss, SIGQUIT) == -1) ||
-		(sigaddset(&feh_ss, SIGINT) == -1))
+		(sigaddset(&feh_ss, SIGINT) == -1) ||
+		(sigaddset(&feh_ss, SIGTTIN) == -1))
 	{
 		weprintf("Failed to set up signal masks");
 		return;
@@ -56,7 +57,8 @@ void setup_signal_handlers()
 		(sigaction(SIGALRM, &feh_sh, NULL) == -1) ||
 		(sigaction(SIGTERM, &feh_sh, NULL) == -1) ||
 		(sigaction(SIGQUIT, &feh_sh, NULL) == -1) ||
-		(sigaction(SIGINT, &feh_sh, NULL) == -1))
+		(sigaction(SIGINT, &feh_sh, NULL) == -1) ||
+		(sigaction(SIGTTIN, &feh_sh, NULL) == -1))
 	{
 		weprintf("Failed to set up signal handler");
 		return;
@@ -75,6 +77,10 @@ void feh_handle_signal(int signo)
 			if (childpid)
 				killpg(childpid, SIGINT);
 			return;
+		case SIGTTIN:
+			// we were probably backgrounded while we were running
+			control_via_stdin = 0;
+			return;
 		case SIGINT:
 		case SIGTERM:
 		case SIGQUIT: