LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-06-2013, 09:22 AM   #1
pro_learner
LQ Newbie
 
Registered: Mar 2013
Posts: 10

Rep: Reputation: Disabled
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
 
Old 03-06-2013, 09:25 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
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.
 
Old 03-06-2013, 09:27 AM   #3
PrinceCruise
Member
 
Registered: Aug 2009
Location: /Universe/Earth/India/Pune
Distribution: Slackware64 -Current
Posts: 890

Rep: Reputation: 186Reputation: 186
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.
 
Old 03-06-2013, 09:35 AM   #4
pro_learner
LQ Newbie
 
Registered: Mar 2013
Posts: 10

Original Poster
Rep: Reputation: Disabled
#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;

}
 
Old 03-06-2013, 09:37 AM   #5
pro_learner
LQ Newbie
 
Registered: Mar 2013
Posts: 10

Original Poster
Rep: Reputation: Disabled
but how to invoke the application from child and as m new to linux plz clear m done the pro write or nt
 
Old 03-06-2013, 09:41 AM   #6
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573

Rep: Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142
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 View Post
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?

Last edited by suicidaleggroll; 03-06-2013 at 09:43 AM.
 
Old 03-06-2013, 10:01 AM   #7
PrinceCruise
Member
 
Registered: Aug 2009
Location: /Universe/Earth/India/Pune
Distribution: Slackware64 -Current
Posts: 890

Rep: Reputation: 186Reputation: 186
Quote:
Originally Posted by pro_learner View Post
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.
 
Old 03-06-2013, 05:43 PM   #8
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,361

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
@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
 
Old 03-11-2013, 11:17 AM   #9
pro_learner
LQ Newbie
 
Registered: Mar 2013
Posts: 10

Original Poster
Rep: Reputation: Disabled
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

Last edited by pro_learner; 03-11-2013 at 11:18 AM.
 
Old 03-11-2013, 11:27 AM   #10
pro_learner
LQ Newbie
 
Registered: Mar 2013
Posts: 10

Original Poster
Rep: Reputation: Disabled
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?
 
Old 03-12-2013, 09:18 PM   #11
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,361

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


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
killng parent process without killing child process (Linux C programming) lettuce84@naver.com Linux - Newbie 3 07-24-2015 08:37 AM
Forked Child Process Inherits Library Linkage from Parent Process (All Unix Flavors) Embedded_guy Linux - General 3 11-14-2012 08:12 AM
Sending Signal from Child Process to Parent Process : Not getting desired output thelink123 Linux - General 4 10-26-2012 09:05 PM
parent process to wait foe child process to comelet priyas Linux - Kernel 2 03-01-2012 08:52 AM
Bash Scripting - child process affecting parent process mthaddon Linux - General 1 05-02-2004 01:19 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:45 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration