// // Cforall Version 1.0.0 Copyright (C) 2022 University of Waterloo // // The contents of this file are covered under the licence agreement in the // file "LICENCE" distributed with Cforall. // // fork+exec.cfa -- Check that we can use fork+exec to test parameters. // // Author : Thierry Delisle // Created On : Wed Sep 27 10:44:38 2022 // Last Modified By : // Last Modified On : // Update Count : // #include "fork+exec.hfa" int main(int argc, char * argv[]) { check_main(argv[0]); printf("arguments are:\n"); if(argc == 1) printf(" None\n"); for(int i = 1; i < argc; i++) { printf(" '%s'\n", argv[i]); } printf("Success!\n"); fflush(stdout); return 0; } int true_main(const char * path, char * env[]) { printf("no arg:\n"); if(pid_t child = strict_fork(); child == 0) { int ret = execle(path, path, (const char*)0p, env); if(ret < 0) { fprintf(stderr, "Execl 1 returned with error: %d '%s'\n", errno, strerror(errno)); exit(1); } } else { int status = do_wait(child); print_status(status); } printf("1 arg:\n"); if(pid_t child = strict_fork(); child == 0) { int ret = execle(path, path, "Hello World!", (const char*)0p, env); if(ret < 0) { fprintf(stderr, "Execl 2 returned with error: %d '%s'\n", errno, strerror(errno)); exit(1); } } else { int status = do_wait(child); print_status(status); } printf("5 arg:\n"); if(pid_t child = strict_fork(); child == 0) { int ret = execle(path, path, "Hi,", "my", "name", "is", "Fred", (const char*)0p, env); if(ret < 0) { fprintf(stderr, "Execl 3 returned with error: %d '%s'\n", errno, strerror(errno)); exit(1); } } else { int status = do_wait(child); print_status(status); } printf("All Done!\n"); return 0; }