1/** \file 2 * \brief Example spawn application 3 */ 4 5/* 6 * Copyright (c) 2010, ETH Zurich. 7 * All rights reserved. 8 * 9 * This file is distributed under the terms in the attached LICENSE file. 10 * If you do not find this file, copies can be found by writing to: 11 * ETH Zurich D-INFK, Haldeneggsteig 4, CH-8092 Zurich. Attn: Systems Group. 12 */ 13 14#include <stdio.h> 15#include <string.h> 16 17#include <barrelfish/barrelfish.h> 18#include <barrelfish/spawn_client.h> 19 20#define MAXPATH 256 21 22int main(int argc, char *argv[]) 23{ 24 errval_t err; 25 coreid_t mycore = disp_get_core_id(); 26 27 debug_printf("This is xmpl-spawn on core %d\n", mycore); 28 29 int num_spawns = -1; 30 int num_cores = -1; 31 if (argc == 3) { 32 num_spawns = atoi(argv[1]); 33 num_cores = atoi(argv[2]); 34 35 char path[MAXPATH]; 36 snprintf(path, MAXPATH, "examples/%s", argv[0]); 37 argv[1] = NULL; 38 39 struct capref ret_domain_cap; 40 41 coreid_t core = 0; 42 for (int i = 0; i < num_spawns; i++, core++) { 43 core %= num_cores; 44 /* 45 Signature for spawn_program is: 46 47 errval_t spawn_program(coreid_t coreid, const char *path, 48 char *const argv[], char *const envp[], 49 spawn_flags_t flags, struct capref *ret_domain_cap) 50 */ 51 err = spawn_program(core, path, argv, NULL, 0, 52 &ret_domain_cap); 53 if (err_is_fail(err)) { 54 DEBUG_ERR(err, "failed spawn %d on core %d", i, core); 55 } else { 56 debug_printf("program %d on core %"PRIuCOREID" spawned \n", i, core); 57 } 58 } 59 } else { 60 debug_printf("not spawning any programs\n"); 61 } 62 63 debug_printf("Finished\n"); 64} 65