how many times the printf will be executed ?

S

sumedh.....

main()
{
int i;
fork();
fork();
fork();
printf("----");
}

how many times the printf will be executed .
a.3
b. 6
c.5
d. 8
 
M

Mark Bluemel

sumedh..... said:
main()
{
int i;
fork();
fork();
fork();
printf("----");
}

how many times the printf will be executed .
a.3
b. 6
c.5
d. 8
In any given instance of the program printf will be executed once.

What is fork()? It's not part of the C language specification, and you
haven't given us any definition of it.

Ask the question on a relevant forum. Good luck in the interview or with
your assignment.
 
S

sumedh.....

In any given instance of the program printf will be executed once.

What is fork()? It's not part of the C language specification, and you
haven't given us any definition of it.

Ask the question on a relevant forum. Good luck in the interview or with
your assignment.

fork() for your knowledge is a function call that creates child
process.. if it creates a child process then will it go and excute the
child process leaving behind the main()...
that is a relevant question. As, the main() process can die while
child process is executing then in that case you have printf executed
0times :)
 
J

Jens Thoms Toerring

sumedh..... said:
main()
{
int i;
fork();
fork();
fork();
printf("----");
}
how many times the printf will be executed .
a.3
b. 6
c.5
d. 8

1) Wrong newsgroup: fork() isn't part of the C standard,
so discussing it's behaviour here would be off-topic.
Try e.g. comp.unix.programmers instead.
2) Did you run the program to see how often it prints?
Adding a '\n' to the output or using puts() instead
of printf() would definitely help as would including
<stdio.h> (as well as a header that declares fork()).
And if you're at it also use 'int main(void) and add
a final line with 'return 0;'.
3) Neither here nor in comp.unix.programmer people are
too enthusiastic about doing other peoples homework...

Regards, Jens
 
S

sumedh.....

1) Wrong newsgroup: fork() isn't part of the C standard,
so discussing it's behaviour here would be off-topic.
Try e.g. comp.unix.programmers instead.
2) Did you run the program to see how often it prints?
Adding a '\n' to the output or using puts() instead
of printf() would definitely help as would including
<stdio.h> (as well as a header that declares fork()).
And if you're at it also use 'int main(void) and add
a final line with 'return 0;'.
3) Neither here nor in comp.unix.programmer people are
too enthusiastic about doing other peoples homework...

Regards, Jens

sorry
 
J

John Bode

fork() for your knowledge is a function call that creates child
process.. if it creates a child process then will it go and excute the
child process leaving behind the main()...
that is a relevant question. As, the main() process can die while
child process is executing then in that case you have printf executed
0times :)- Hide quoted text -

- Show quoted text -

Fork bombs are bad, mmm'kay?
 
M

Mark Bluemel

sumedh..... said:
fork() for your knowledge is a function call that creates child
process..

Actually I've been working professionally with Unix for a very long
time. The point is that as far as this newsgroup is concerned, fork() is
off-topic.
if it creates a child process then will it go and excute the
child process leaving behind the main()...
that is a relevant question. As, the main() process can die while
child process is executing then in that case you have printf executed
0times :)

<Off-topic>
Really? I don't think so, and neither does the author of the reference
text I just reviewed...
</Off-topic>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top