By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,952 Members | 949 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,952 IT Pros & Developers. It's quick & easy.

how many times the printf will be executed ?

P: n/a
main()
{
int i;
fork();
fork();
fork();
printf("----");
}

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

Aug 14 '07 #1
Share this Question
Share on Google+
6 Replies


P: n/a
sumedh..... wrote:
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.
Aug 14 '07 #2

P: n/a
On Aug 14, 3:55 pm, Mark Bluemel <mark_blue...@pobox.comwrote:
sumedh..... wrote:
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.
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 :)

Aug 14 '07 #3

P: n/a
sumedh..... <su**********@gmail.comwrote:
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
--
\ Jens Thoms Toerring ___ jt@toerring.de
\__________________________ http://toerring.de
Aug 14 '07 #4

P: n/a
On Aug 14, 4:02 pm, j...@toerring.de (Jens Thoms Toerring) wrote:
sumedh..... <sumedhsak...@gmail.comwrote:
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
--
\ Jens Thoms Toerring ___ j...@toerring.de
\__________________________ http://toerring.de
sorry

Aug 14 '07 #5

P: n/a
On Aug 14, 5:59 am, "sumedh....." <sumedhsak...@gmail.comwrote:
On Aug 14, 3:55 pm, Mark Bluemel <mark_blue...@pobox.comwrote:


sumedh..... wrote:
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.

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?

Aug 14 '07 #6

P: n/a
sumedh..... wrote:
On Aug 14, 3:55 pm, Mark Bluemel <mark_blue...@pobox.comwrote:
>sumedh..... wrote:
>> 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.

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>
Aug 14 '07 #7

This discussion thread is closed

Replies have been disabled for this discussion.