LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
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, 10: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, 10:25 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974
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, 10:27 AM   #3
PrinceCruise
Member
 
Registered: Aug 2009
Location: /Universe/Earth/India/Pune
Distribution: Slackware64 -Current
Posts: 889

Rep: Reputation: 182Reputation: 182
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, 10: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, 10: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, 10:41 AM   #6
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,258

Rep: Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947
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 10:43 AM.
 
Old 03-06-2013, 11:01 AM   #7
PrinceCruise
Member
 
Registered: Aug 2009
Location: /Universe/Earth/India/Pune
Distribution: Slackware64 -Current
Posts: 889

Rep: Reputation: 182Reputation: 182
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, 06:43 PM   #8
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,240

Rep: Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324
@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, 12:17 PM   #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 12:18 PM.
 
Old 03-11-2013, 12:27 PM   #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, 10:18 PM   #11
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,240

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


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 09:37 AM
Forked Child Process Inherits Library Linkage from Parent Process (All Unix Flavors) Embedded_guy Linux - General 3 11-14-2012 09:12 AM
Sending Signal from Child Process to Parent Process : Not getting desired output thelink123 Linux - General 4 10-26-2012 10:05 PM
parent process to wait foe child process to comelet priyas Linux - Kernel 2 03-01-2012 09:52 AM
Bash Scripting - child process affecting parent process mthaddon Linux - General 1 05-02-2004 02:19 PM


All times are GMT -5. The time now is 03:21 AM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration