Skip to content
Snippets Groups Projects
Select Git revision
  • master default protected
  • unstable
  • processes_wip
  • clang
  • cmake
  • cmake-old
  • sd-fix
  • shield_stackX
  • compute-unit-v2
  • con-rig
  • testing_ram_cu_v2
  • parafoil-sensortile
  • angel-swi
  • ignition
  • miosix-2.22
  • alderaan-v1
16 results

main.cpp

Blame
  • main.cpp 863 B
    
    #include <cstdio>
    #include <sys/wait.h>
    #include <signal.h>
    #include "miosix.h"
    #include "kernel/process.h"
    #include "app_template/prog3.h"
    
    using namespace std;
    using namespace miosix;
    
    void ledThread(void *)
    {
        for(;;)
        {
            ledOn();
            Thread::sleep(200);
            ledOff();
            Thread::sleep(200);
        }
    }
    
    int main()
    {
        Thread::create(ledThread,STACK_MIN);
        
        ElfProgram prog(reinterpret_cast<const unsigned int*>(main_elf),main_elf_len);
        for(;;)
        {
            getchar();
            Process::create(prog);
            int ec;
            pid_t pid=Process::wait(&ec);
            iprintf("Process %d terminated\n",pid);
            if(WIFEXITED(ec))
            {
                iprintf("Exit code is %d\n",WEXITSTATUS(ec));
            } else if(WIFSIGNALED(ec)) {
                if(WTERMSIG(ec)==SIGSEGV) iprintf("Process segfaulted\n");
            }
        }
    }