Multicore Programming – using posix_spawn() to create processes (C++)
April 24, 2016
Categorised in: C++ Codes, OOMP Codes
/* Using multicore programming implement posix_spawn() function to create a process. */ /*Execution: oct@CCOMPL08-10:~$ g++ templ.cpp -o mat.o oct@CCOMPL08-10:~$ g++ multicore.cpp -lpthread oct@CCOMPL08-10:~$ ./a.out */ #include<iostream> #include<spawn.h> #include<sys/types.h> #include<sys/wait.h> using namespace std; int main(int argc, char *argv[], char *env[]){ pid_t pid, pid1; int status, status1; status = posix_spawn(&pid, "/bin/ls", NULL, NULL, argv, env); cout<<"------------------------ \n"; if(status == 0) cout<<"Process created successfully... \n"; cout<<"------------------------ \n"; wait(&pid); status1 = posix_spawn(&pid1, "mat.o", NULL, NULL, argv, env); cout<<"------------------------ \n"; if(status1 == 0) cout<<"Process created successfully... \n"; cout<<"------------------------ \n"; wait(&pid1); return 0; }
Pratik Kataria is currently learning Springboot and Hibernate.
Technologies known and worked on: C/C++, Java, Python, JavaScript, HTML, CSS, WordPress, Angular, Ionic, MongoDB, SQL and Android.
Softwares known and worked on: Adobe Photoshop, Adobe Illustrator and Adobe After Effects.