1 /* 2 * A test of executing code in new tasks and threads. 3 * 4 * Copyright (C) 2022, 2023 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 /* Obtain the common notifier. */ 45 46 process_notifier_t *notifier = process_notify_task(); 47 48 /* Create a new process structure. */ 49 50 process_t process; 51 52 process_init(&process); 53 54 for (int i = 1; i <= num_processes; i++) 55 { 56 printf("[%d/%d] Start process...\n", i, num_processes); 57 58 /* Start a process for the given program. */ 59 60 err = process_start(&process, argc - 2, (const char **) argv + 2); 61 62 if (err) 63 { 64 printf("Could not start process: %s\n", l4sys_errtostr(err)); 65 return 1; 66 } 67 68 printf("Finished program initiation.\n"); 69 70 /* Subscribe to the process for notifications. */ 71 72 err = process_notify_subscribe(&process, NOTIFY_TASK_ALL, notifier); 73 74 if (err) 75 { 76 printf("Could not subscribe to process: %s\n", l4sys_errtostr(err)); 77 return 1; 78 } 79 80 /* Wait for a signal from the process. */ 81 82 err = process_notify_wait_process(&process, notifier); 83 84 if (err) 85 { 86 printf("Could not wait for process: %s\n", l4sys_errtostr(err)); 87 return 1; 88 } 89 90 notify_flags_t flags = process_notifications(&process); 91 notify_values_t values = process_notification_values(&process); 92 93 printf("[%d/%d] End process (flags %" pFMTnotify_flags "x values: %ld, %ld)\n", i, num_processes, flags, values.sig, values.val); 94 95 process_close(&process); 96 } 97 98 process_notify_close(notifier); 99 100 printf("End of test.\n"); 101 return 0; 102 } 103 104 /* vim: tabstop=2 expandtab shiftwidth=2 105 */