Trigger a hot reload / full restart based on SIGUSR1 and SIGUSR2 (#5453)

diff --git a/packages/flutter_tools/lib/src/commands/run.dart b/packages/flutter_tools/lib/src/commands/run.dart
index 0ad84a0..911345e 100644
--- a/packages/flutter_tools/lib/src/commands/run.dart
+++ b/packages/flutter_tools/lib/src/commands/run.dart
@@ -20,7 +20,6 @@
 import 'build_apk.dart';
 import 'install.dart';
 import 'trace.dart';
-import '../base/os.dart';
 
 abstract class RunCommandBase extends FlutterCommand {
   RunCommandBase() {
@@ -69,10 +68,9 @@
                       defaultsTo: false,
                       help: 'Run with support for hot reloading.');
 
-    // Option to enable control over a named pipe.
-    argParser.addOption('control-pipe',
-                        hide: true,
-                        help: 'Specify a named pipe to receive commands on.');
+    // Option to write the pid to a file.
+    argParser.addOption('pid-file',
+                        help: 'Specify a file to write the process id to.');
 
 
     // Hidden option to enable a benchmarking mode. This will run the given
@@ -142,23 +140,13 @@
         printError('Hot mode is not supported by this device.');
         return 1;
       }
-    } else {
-      if (argResults['control-pipe'] != null) {
-        printError('--control-pipe requires --hot');
-        return 1;
-      }
     }
 
-    String pipePath = argResults['control-pipe'];
-    File pipe;
-    if (pipePath != null) {
-      try {
-        // Attempt to create the pipe.
-        os.makePipe(pipePath);
-      } catch (_) { /* ignore */ }
-      pipe = new File(pipePath);
+    String pidFile = argResults['pid-file'];
+    if (pidFile != null) {
+      // Write our pid to the file.
+      new File(pidFile).writeAsStringSync(pid.toString());
     }
-
     ResidentRunner runner;
 
     if (argResults['hot']) {
@@ -166,7 +154,6 @@
         deviceForCommand,
         target: targetFile,
         debuggingOptions: options,
-        pipe: pipe
       );
     } else {
       runner = new RunAndStayResident(
diff --git a/packages/flutter_tools/lib/src/hot.dart b/packages/flutter_tools/lib/src/hot.dart
index 80d98a2..fa98e83 100644
--- a/packages/flutter_tools/lib/src/hot.dart
+++ b/packages/flutter_tools/lib/src/hot.dart
@@ -118,8 +118,7 @@
     Device device, {
     String target,
     DebuggingOptions debuggingOptions,
-    bool usesTerminalUI: true,
-    this.pipe
+    bool usesTerminalUI: true
   }) : super(device,
              target: target,
              debuggingOptions: debuggingOptions,
@@ -132,33 +131,6 @@
   String _projectRootPath;
   Set<String> _startupDependencies;
   final AssetBundle bundle = new AssetBundle();
-  final File pipe;
-
-  Future<String> _readFromControlPipe() async {
-    final Stream<List<int>> stream = pipe.openRead();
-    final List<int> bytes = await stream.first;
-    final String string = new String.fromCharCodes(bytes).trim();
-    return string;
-  }
-
-  Future<Null> _startReadingFromControlPipe() async {
-    if (pipe == null)
-      return;
-
-    while (true) {
-      // This loop will only exit if _readFromControlPipe throws an exception.
-      // If no exception is thrown this will keep the flutter command running
-      // until it is explicitly stopped via some other mechanism, for example,
-      // ctrl+c or sending "q" to the control pipe.
-      String result = await _readFromControlPipe();
-      printStatus('Control pipe received "$result"');
-      await processTerminalInput(result);
-      if (result.toLowerCase() == 'q') {
-        printStatus("Finished reading from control pipe");
-        break;
-      }
-    }
-  }
 
   @override
   Future<int> run({
@@ -300,8 +272,6 @@
     _loaderShowMessage('Launching...');
     await _launchFromDevFS(_package, _mainPath);
 
-    _startReadingFromControlPipe();
-
     printStatus('Application running.');
 
     setupTerminal();
diff --git a/packages/flutter_tools/lib/src/resident_runner.dart b/packages/flutter_tools/lib/src/resident_runner.dart
index 166f729..d212009 100644
--- a/packages/flutter_tools/lib/src/resident_runner.dart
+++ b/packages/flutter_tools/lib/src/resident_runner.dart
@@ -65,6 +65,14 @@
       await cleanupAfterSignal();
       exit(0);
     });
+    ProcessSignal.SIGUSR1.watch().listen((ProcessSignal signal) async {
+      printStatus('Caught SIGUSR1');
+      await restart(fullRestart: false);
+    });
+    ProcessSignal.SIGUSR2.watch().listen((ProcessSignal signal) async {
+      printStatus('Caught SIGUSR2');
+      await restart(fullRestart: true);
+    });
   }
 
   Future<Null> startEchoingDeviceLog() async {