1 /* 2 * A test of executing code in new tasks and threads. 3 * 4 * Copyright (C) 2022, 2023, 2024 Paul Boddie <paul@boddie.org.uk> 5 * 6 * This program is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU General Public License as 8 * published by the Free Software Foundation; either version 2 of 9 * the License, or (at your option) any later version. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program; if not, write to the Free Software 18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, 19 * Boston, MA 02110-1301, USA 20 */ 21 22 #include <l4/sys/err.h> 23 24 #include <fsclient/process.h> 25 #include <systypes/format.h> 26 27 #include <stdio.h> 28 #include <stdlib.h> 29 30 31 32 int main(int argc, char *argv[]) 33 { 34 long err; 35 36 if (argc < 3) 37 { 38 printf("Need a number and the program to run.\n"); 39 return 1; 40 } 41 42 int num_processes = atoi(argv[1]); 43 44 for (int i = 1; i <= num_processes; i++) 45 { 46 printf("[%d/%d] Start process...\n", i, num_processes); 47 48 /* Start a process for the given program. */ 49 50 process_t *process; 51 52 err = process_spawn(argc - 2, (const char **) argv + 2, NULL, NULL, &process); 53 54 if (err) 55 { 56 printf("Could not start process: %s\n", l4sys_errtostr(err)); 57 return 1; 58 } 59 60 printf("Finished program initiation.\n"); 61 62 /* Wait for a signal from the process. */ 63 64 notify_flags_t flags; 65 notify_values_t values; 66 67 err = process_wait(process, &flags, &values); 68 69 if (err) 70 { 71 printf("Could not wait for process: %s\n", l4sys_errtostr(err)); 72 return 1; 73 } 74 75 printf("[%d/%d] End process (flags %" pFMTnotify_flags "x values: %ld, %ld)\n", i, num_processes, flags, values.sig, values.val); 76 } 77 78 printf("End of test.\n"); 79 return 0; 80 } 81 82 /* vim: tabstop=2 expandtab shiftwidth=2 83 */