c - How to run a background process before all foreground processes or a particular foreground process? -
this program system.c
#include <stdio.h> #include <stdlib.h> int main() { system("./client &"); printf("we in main program\n"); printf("we in main program\n"); printf("we in main program\n"); printf("we in main program\n"); printf("we in main program\n"); return 0; }
this client.c
#include <stdio.h> int main() { printf("we in background process\n"); { //doing process on message queue receive messages } while (1); return 0; }
how output of ./system running linux terminal below one
we in background process in main program in main program in main program in main program in main program
can please explain more clarity?
maybe have @ , inspire yourself.
#include <stdio.h> #include <stdlib.h> #include <unistd.h> int main() { int pid; int status; pid = fork(); if (pid == -1) { // handle error } if (pid == 0) { // exec child process execl("./client", "client", null); } else { wait(&status); } printf("we in main program\n"); printf("we in main program\n"); printf("we in main program\n"); printf("we in main program\n"); printf("we in main program\n"); return 0; }
Comments
Post a Comment