LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Create a 5 child process from a common parent and launch different applications from (https://www.linuxquestions.org/questions/linux-newbie-8/create-a-5-child-process-from-a-common-parent-and-launch-different-applications-from-4175452965/)

pro_learner 03-06-2013 09:22 AM

Create a 5 child process from a common parent and launch different applications from
 
Create a 5 child process from a common parent and launch different
applications from the children processes you
may launch pdf viewer,
kwrite, dolphin and gcc parent
process must use waitpid() to
collect the termination status of the child process waitpid()
must be called after all the children are created and the parent has
completed its work real work,if any. You must interpret the exit code of the
cleanedup
processes – you must cover all the possible scenarios

acid_kewpie 03-06-2013 09:25 AM

Per the LQ Rules, please do not post homework assignments verbatim. We're happy to assist if you have specific questions or have hit a stumbling point, however. Let us know what you've already tried and what references you have used (including class notes, books, and Google searches) and we'll do our best to help. Also, keep in mind that your instructor might also be an LQ member.

PrinceCruise 03-06-2013 09:27 AM

Homework? Let us know what code you have written so far and where are you facing issue.

EDIT: Mod, you beat me in typing.

Regards.

pro_learner 03-06-2013 09:35 AM

#include<sys/types.h>
#include<unistd.h>
#include<sys/wait.h>
#include<stdio.h>
#include<stdlib.h>


int main()
{

int ret,status=0;

unsigned long int i=0;

while(i++<5){

// printf("I am in parent process context");
ret = fork();
//printf("pid is %d ppid is % ret value is %d \n", getpid(), getppid(), ret);

if(ret<0){

perror("error in fork");
printf("the final value of i is %lu\n", i);

exit(1);
}

if(ret>0){
printf("I am in parent process context\n");
printf("in parent .. ppid is %lu ...and pid is %lu\n",
getppid(),getpid());


//++i;
continue;
}

if(ret==0) {
printf("I am in child process context\n");
printf("in child .. ppid is %lu ...and pid is %lu\n",
getppid(),getpid());



exit(0);
}

}//while



if(ret>0)
{
while(1){
ret = waitpid(-1,&status,0);
if(ret>0){

if(WIFEXITED(status))
{
if(WEXITSTATUS(status) == 0){
}
else{
}
}
else{

if(WIFSIGNALED(status))
{
printf("signal that terminated is %d\n",WTERMSIG(status));
}

}
}//ret>0

if(ret<0) { exit(0); }
//if(ret<0) {

//if(flag!=0) exit(11);
//else break;
// }


}
}

return 0;

}

pro_learner 03-06-2013 09:37 AM

but how to invoke the application from child and as m new to linux plz clear m done the pro write or nt

suicidaleggroll 03-06-2013 09:41 AM

Please take an extra two seconds to use proper spelling, punctuation, and grammar when typing your post. I have absolutely no idea what this is supposed to say:

Quote:

Originally Posted by pro_learner (Post 4906021)
as m new to linux plz clear m done the pro write or nt

If you can't be bothered to make your questions legible, why should we bother responding?

PrinceCruise 03-06-2013 10:01 AM

Quote:

Originally Posted by pro_learner (Post 4906021)
but how to invoke the application from child and as m new to linux plz clear m done the pro write or nt

If you want to invoke some system tasks from within child, use exec (execlp/execvp/execle) calls.
See one example code I wrote some days before to help understand this. The child is calling another program with executable name hello. You may pass the arguments here, like the system() call. :-

Quote:

int main(void)
{
int pid;

pid = fork();

if (pid == 0)
{
//char *arglist[3] = {"test", "test1", NULL};
printf("Child : Executing hello .... \n");
execlp("./hello", "test", "test1", 0); // With execlp we need to pass argument in itself.
perror("There is an error -");
}
else
{
int status;
wait(&status);
if (WIFEXITED(status))
{
printf("This is Parent and the child exited with status - %d", status); //WEXITSTATUS(status) is correct
printf("\n");
}

//sleep(10);
}

return 0;
}
let know the progress, you're doing fine.

Regards.

chrism01 03-06-2013 05:43 PM

@pro_learner; please use code tags https://www.linuxquestions.org/quest...do=bbcode#code when posting and ensure code is indented between {...} for ease of reading.

Welcome to LQ :)

pro_learner 03-11-2013 11:17 AM

i gave priority 10 to certain process with fifo policies...bt it showing priority as -11 and not even the policies changing

e.g chrt -f -p 10 <pid>
itz showing prio. as -11 and polices round robin

i jst encountered slow down in system performance...somewhat freeze

pro_learner 03-11-2013 11:27 AM

problem2:

i create several instances of a process like- ex 1000&,ex 1000&,ex 1000&,ex 1000&,ex 1000&
and ex 2500& and 2000&

when m doing pkill -SIGTERM ex only 1000& instances getting killed bt nt other two...why all processes not terminating?

chrism01 03-12-2013 09:18 PM

Please write in proper English as requested above, and more clearly explain exactly what you did.


All times are GMT -5. The time now is 08:13 PM.