diff --git a/bin/webpack.js b/bin/webpack.js
index <HASH>..<HASH> 100644
--- a/bin/webpack.js
+++ b/bin/webpack.js
@@ -350,16 +350,14 @@ function processOptions(options) {
 				process.stdout.write(statsString + "\n");
 		}
 		if(!options.watch && stats.hasErrors()) {
-			process.on("exit", function() {
-				process.exit(2); // eslint-disable-line
-			});
+			process.exitCode = 2;
 		}
 	}
 	if(firstOptions.watch || options.watch) {
 		var watchOptions = firstOptions.watchOptions || firstOptions.watch || options.watch || {};
 		if(watchOptions.stdin) {
 			process.stdin.on("end", function() {
-				process.exit(0); // eslint-disable-line
+				process.exit(); // eslint-disable-line
 			});
 			process.stdin.resume();
 		}
Fix exit code and ELIFECYCLE error

Due to race condition (process.exit() called multiple times) sometimes process fails with error ELIFECYCLE. In that case process exits with exit code 0 but should exit with exit code 2. This change ensures that the race condition can not happened.