Distro for Linux for WebAssembly
at main 53 lines 1.2 kB view raw
1#define _GNU_SOURCE 2#include <stdlib.h> 3#include <sched.h> 4#include <stdio.h> 5#include <sys/utsname.h> 6#include <unistd.h> 7 8static int foo = 0; 9 10int other(void *arg) { 11 printf("hello from other thread: %d\n", foo); 12 return 0; 13} 14 15int main(int argc, char *argv[]) { 16 printf("Hello, world!\n"); 17 18 printf("pid = %d\n", getpid()); 19 20 struct utsname sysinfo; 21 if (uname(&sysinfo) == -1) { 22 perror("uname"); 23 return 1; 24 } 25 26 printf("%s %s %s\n", sysinfo.sysname, sysinfo.release, sysinfo.version); 27 28 printf("argc = %d\n", argc); 29 for (int i = 0; i < argc; i++) 30 printf("argv[%d] = %s\n", i, argv[i]); 31 for (int i = 0; environ[i]; i++) 32 printf("environ[%d] = %s\n", i, environ[i]); 33 34 foo = 1; 35 void* stack = malloc(4096); 36 if (!stack) { 37 perror("malloc"); 38 return 1; 39 } 40 41 if (clone(other, stack + 4096, CLONE_VM | CLONE_VFORK, NULL) == -1) { 42 perror("clone"); 43 return 1; 44 } 45 46 free(stack); 47 48 printf("idling forever\n"); 49 for (;;) 50 sched_yield(); 51 52 return 0; 53}