Browse Source

kill: handle multiple pids

K. Lange 2 years ago
parent
commit
e60dae074c
1 changed files with 11 additions and 5 deletions
  1. 11 5
      apps/kill.c

+ 11 - 5
apps/kill.c

@@ -114,19 +114,25 @@ int main(int argc, char * argv[]) {
 		i++;
 	}
 
-	if (i < argc) {
+	if (i == argc) {
+		usage(argv);
+		return 1;
+	}
+
+	int retval = 0;
+
+	for (; i < argc; ++i) {
 		pid = atoi(argv[i]);
 		if (pid) {
 			if (kill(pid, signum) < 0) {
 				fprintf(stderr, "%s: (%d) %s\n", argv[0], pid, strerror(errno));
+				retval = 1;
 			}
 		} else {
 			fprintf(stderr, "%s: invalid pid (%s)\n", argv[0], argv[i]);
+			retval = 1;
 		}
-	} else {
-		usage(argv);
-		return 1;
 	}
 
-	return 0;
+	return retval;
 }