Powered by Invision Power Board


  Reply to this topicStart new topicStart Poll

> fork() problem, Gives unexpected output
asinro
Posted: Mar 11 2005, 09:33 AM
Quote Post


Newbie
*

Group: Members
Posts: 1
Member No.: 854
Joined: 11-March 05



hi
When I run the program below it gives unexpected result
Why this program gives that type of output?
thanks

CODE

#include <stdio.h>
main()
{
FILE *outfile;

if ( (outfile=fopen("myout","w"))==NULL)
{
 perror ("P6.C");
 exit(2);
}

if (fork()==0)
 fprintf(outfile,"%s\n","output from the child");

if (fclose(outfile)==EOF)
 perror("P6.C");
else
{
 sleep(3);
 fprintf(outfile,"%s\n","output from the parent");
 fclose(outfile);
}
}
PMEmail Poster
Top
nrutter
Posted: Mar 11 2005, 11:50 AM
Quote Post


Newbie
*

Group: Members
Posts: 7
Member No.: 721
Joined: 17-December 04



What is so unexpected about the output?

What are you expecting to get?
PMEmail Poster
Top
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:
« Next Oldest | Programming/Languages | Next Newest »

Topic Options Reply to this topicStart new topicStart Poll

 



[ Script Execution time: 0.2827 ]   [ 12 queries used ]   [ GZIP Enabled ]




Partners: Cambridge Plus :: <Link Available> :: Electronic Circuit Design :: <Link Available>
Unix Man Pages / Linux Man Pages :: HiFi Forum :: SIP VoIP Phone & Provider Reviews :: UNIX/Linux Forum Archives

More info on advertising on Unix/Linux Forum