473,394 Members | 1,752 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

how many times the printf will be executed ?

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
6 3883
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: djskrill | last post by:
Why is the Constructor called 4 times but the Destructor 5 times? I am using MS VC 6. If this has been covered already please let me know. The Code: #include <stdio.h> class MyClass {...
6
by: Christian | last post by:
HI, I have a function that is used to constrain a query: Select COl1, Col2 From MyTable WHERE col1 = ... AND col2 = ... And MyFunction(col1) = ... My problem is that MyFunction is executed...
1
by: Nick Li | last post by:
Hi, I am trying to print a value of a variable multiple times. For example, the value is "*" and I want to print it five times, like "*****". Can somebody show me a easy way to do it? Thanks...
9
by: Eric Lilja | last post by:
Hello, I have two code snippets I want you to look at. My program compiles without warnings (warning level set to max, gcc 3.4.3) with either snippet but the latter one causes a segfault at...
10
by: Mike | last post by:
I know this sounds strange but I am at a loss. I am calling a simple funtion that opens a connection to a SQL Server 2000 database and executes an Insert Statement. private void...
2
by: Torben Philippsen | last post by:
Hi, I have a very simple searchform (an asp:textbox and a asp:button) I have enabled autopostback for the textbox to be able to execute the search method when the user hits the enter key. ...
0
by: grbCPPUsr | last post by:
I am new to Python. I would like to use Python for the specialized purpose of dynamic expressions parsing & evaluation in my C++ application. I would like to encapsulate the expressions to be...
1
by: GS | last post by:
the windows form application works but the eventhandler for binding source postionChanged got executed too many times: 12 times from saveitemclicked for the data navigator many time from additem ...
2
by: hari | last post by:
Hi all, suppose a hex value is there(say 3B), this needs to be expanded. Suppose if this 3B(0011 1011) needs to be expanded by 3 times, then each bit should be expanded by 3 times(000000111111...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.