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 - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 07-11-2009, 09:31 PM   #1
bandaru_sivakrishna
LQ Newbie
 
Registered: Jul 2009
Posts: 13

Rep: Reputation: 0
vfork syscall


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

void main()
{
printf("\nTEST THE FORK SYS CALL\n");
vfork();
vfork();
vfork();
printf("\nhello world\n");
}


Note: the output is "hello world" print only 2 times why?
 
Old 07-12-2009, 04:52 AM   #2
Valery Reznic
ELF Statifier author
 
Registered: Oct 2007
Posts: 676

Rep: Reputation: 137Reputation: 137
Quote:
Originally Posted by bandaru_sivakrishna View Post
#include<stdio.h>
#include<sys/types.h>
#include<unistd.h>

void main()
{
printf("\nTEST THE FORK SYS CALL\n");
vfork();
vfork();
vfork();
printf("\nhello world\n");
}


Note: the output is "hello world" print only 2 times why?
Add
Code:
exit(0)
after last printf and it will work as it should be
 
Old 07-13-2009, 05:11 PM   #3
x_terminat_or_3
Member
 
Registered: Mar 2007
Location: Plymouth, UK
Distribution: Fedora Core, RHEL, Arch
Posts: 342

Rep: Reputation: 38
shouldn't that be

Code:
_exit(0);
when inside a child?
 
Old 07-13-2009, 11:21 PM   #4
Valery Reznic
ELF Statifier author
 
Registered: Oct 2007
Posts: 676

Rep: Reputation: 137Reputation: 137
Quote:
Originally Posted by x_terminat_or_3 View Post
shouldn't that be

Code:
_exit(0);
when inside a child?
Yes and no.

After reading
http://linux.die.net/man/2/vfork

I realized that code is wrong: after vfork only exec* or _exit() allowed,
i.e behavour for
Code:
vfork()
printf()
is undefined.

So when I added exit() and it's work it was only by chance()
 
  


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
Syscall problems RepSTOSW Linux - Kernel 3 03-21-2010 11:57 AM
what is the major differences between fork,vfork and clone bandaru_sivakrishna Linux - Software 1 07-07-2009 09:52 AM
How to implement vfork using clone? archieval Linux - Newbie 2 04-24-2007 08:23 PM
vfork: resource temporarily unavailable verbose Linux - General 5 02-04-2007 04:17 AM
fork vs. vfork gearoid Programming 2 11-28-2003 02:51 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 08:30 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