LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 01-20-2009, 10:18 PM   #1
palisetty_suman
Member
 
Registered: Feb 2007
Location: TX, USA
Distribution: fedora
Posts: 191

Rep: Reputation: 33
Thumbs up Please help me


HI ALL,

I have a small question to all really great linux users and administrators. i couldn't understand the following program. can u please explain in short and in easy way. The program is
------------------------------------------------------------------
#include <sys/wait.h>

#define NULL 0

int main (void)
{
if (fork() == 0){ /* This is the child process */
execve("child",NULL,NULL);
/*
execvp("./Child",NULL);
exit(0);
*/
//printf("I am child process\n");
//exit(0);
}

/* Parent code here */
printf("Process[%d]: Parent in execution ...\n", getpid());
sleep(5);
if(wait(NULL) > 0) /* Child terminating */
printf("Process[%d]: Parent detects terminating child \n", getpid());
printf("Process[%d]: Parent terminating ...\n", getppid());

}
------------------------------------------------------------------------
where i did not understand is

1) what is execve("child",NULL,NULL);
2)from --> Sleep(5) TO THE END,I DID NOT UNDERSTAND.
Can anybody help me please. its not tough for u greats but if u explain me,i would be more than blessed. Thanks.
 
Old 01-20-2009, 10:22 PM   #2
Quakeboy02
Senior Member
 
Registered: Nov 2006
Distribution: Debian Linux 11 (Bullseye)
Posts: 3,407

Rep: Reputation: 141Reputation: 141
Looks like a pretty simple homework exercise to me.
 
Old 01-20-2009, 11:12 PM   #3
hjogoo
LQ Newbie
 
Registered: Jan 2009
Posts: 14

Rep: Reputation: 0
It has something to do with forking and process id's .. Why don't you just try the script and see what it does.
 
Old 01-21-2009, 12:57 AM   #4
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
Use better thread titles.
 
Old 01-21-2009, 01:56 AM   #5
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
palisetty;

You did not follow up in your last homework thread-----here:
http://www.linuxquestions.org/questi...9/#post3412997

Giving both threads the same (un-helpful) title was not a good move either.

You CAN get help with homework here, but not like this.......

As for the substance, two questions:

1. Do you know what the code is supposed to do?

2. Where is the function "execve" defined? Do you think that definition might help you understand what is happening?
 
Old 01-21-2009, 02:06 AM   #6
Disillusionist
Senior Member
 
Registered: Aug 2004
Location: England
Distribution: Ubuntu
Posts: 1,039

Rep: Reputation: 98
A couple of things.

First, as Nylex stated, Please use better thread titles than "Please Help". There should be something relating to the thread topic, in this case something like "query with routine in small program - HOMEWORK"

Second, when posting code please enclose it with the CODE tags (by clicking on the # symbol on the Post Thread/Reply to Thread dialogue box) this makes it so much easier to read as it keeps the formating.

Third, please state what you have tried already (including google searches)
 
Old 01-24-2009, 09:33 AM   #7
renjithrajasekaran
Member
 
Registered: Jan 2009
Posts: 29

Rep: Reputation: 15
These links should help you understand better:

sleep()
http://osr507doc.sco.com/en/man/html.C/sleep.C.html

execve()
http://www.cs.ui.ac.id/WebKuliah/IKI...ng_a_File.html

wait()
http://docsrv.sco.com:507/en/man/html.C/wait.C.html

Linux Archive

Last edited by renjithrajasekaran; 01-25-2009 at 03:08 AM.
 
  


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 On
HTML code is Off



LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 07:32 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
Open Source Consulting | Domain Registration