Login
Register
@
Dark Mode
Profile
Edit my Profile
Messages
My favorites
Register
Activity
Q&A
Questions
Unanswered
Tags
Subjects
Users
Ask
Previous Years
Blogs
New Blog
Exams
Dark Mode
Fork() system call.
vikranty2j
asked
in
Operating System
Mar 20
208
views
0
votes
0
votes
main(){
int i,n;
for(int i=0;i<n;i++){
fork();
printf("*");
}
}
How many times ‘*’ will be printed? The answer is not 2^n ? why?
programming-in-c
operating-system
vikranty2j
asked
in
Operating System
Mar 20
by
vikranty2j
208
views
answer
comment
Follow
share this
share
3 Comments
by
chinmay_rajpurohit
commented
Mar 20
reply
Follow
share this
It will vary. Check for n=1,2,3. If you checked this please give what expression you are getting. I am not getting any fixed expression
0
0
by
vikranty2j
commented
Mar 22
reply
Follow
share this
I am getting this expression.
2^(n+1)-2
0
0
by
chinmay_rajpurohit
commented
Mar 23
reply
Follow
share this
getting correct for n=4?? too. if yes then I think this correct
0
0
Please
log in
or
register
to add a comment.
Please
log in
or
register
to answer this question.
1
Answer
0
votes
0
votes
each time the for loop gets executed it prints star(*) two times
=> cuz fork() creates one child and it prints one star and when the control comes back to parent it prints * again
so for n loop executions the answer should be => 2n
kickassakash
answered
Mar 21
by
kickassakash
comment
Follow
share this
1 comment
by
vikranty2j
commented
Mar 22
reply
Follow
share this
No this is not the right answer. Let say n=3 ,then I will be getting 14 stars. I think the general expression is 2^(n+1)-2. I don’t know why.
–1
–1
Please
log in
or
register
to add a comment.
← Previous
Next →
← Previous in category
Next in category →
Related questions
3
votes
3
votes
1
answer
1
indrajeet
asked
in
Operating System
Nov 20, 2016
1,553
views
fork() system call
MY QUESTION IS 1)WHY PRINTF() PRINT VIRTUAL ADDRESS(MENTIONED IN EXPLANTION) NOT PHYSICAL ADDRESS 2) WHY VIRTUAL ADDRESS(O/P OF PRINTF(&VAR)) OF A VARIABLE CHANGES WHEN WE RUN A PROGRAM MANY TIMES Consider the following code fragment: if (fork() = ... process and virtual address of a' doesn't change in child process. Therefore, we get same addresses in both parent and child.
indrajeet
asked
in
Operating System
Nov 20, 2016
by
indrajeet
1.6k
views
operating-system
fork-system-call
programming-in-c
1
vote
1
vote
0
answers
2
Souvik33
asked
in
Operating System
Nov 28, 2022
365
views
Fork System Call and Threads | OS | MSQ
MSQ Consider the following statements, which one of the following is/are TRUE In fork() system call, child process inherits all the open file descriptors of parent process In fork() system call, child process copies the code of the ... system call, child process shares the code of the parent process User level threads shares the code segment of the process
Souvik33
asked
in
Operating System
Nov 28, 2022
by
Souvik33
365
views
operating-system
fork-system-call
unix
process-and-threads
threads
multiple-selects
0
votes
0
votes
2
answers
3
dd
asked
in
Operating System
Sep 15, 2018
754
views
Fork system call,open file table
The fork system call creates new entries in the open file table for the newly created child process. [True / False] [ what is open file table ? ]
dd
asked
in
Operating System
Sep 15, 2018
by
dd
754
views
operating-system
fork-system-call
9
votes
9
votes
2
answers
4
nandini gupta
asked
in
Operating System
Aug 12, 2018
3,861
views
Fork System Call
A process execute the code: main() { fork(); fork() && fork() || fork(); fork(); printf("Hi"); } The number of times "Hi" will be printed is
nandini gupta
asked
in
Operating System
Aug 12, 2018
by
nandini gupta
3.9k
views
operating-system
fork-system-call
Subscribe to GATE CSE 2024 Test Series
Subscribe to GO Classes for GATE CSE 2024
Quick search syntax
tags
tag:apple
author
user:martin
title
title:apple
content
content:apple
exclude
-tag:apple
force match
+apple
views
views:100
score
score:10
answers
answers:2
is accepted
isaccepted:true
is closed
isclosed:true
Recent Posts
GO Classes NIELIT Test Series For 2023
Interview Experience : MTech Research(Machine Learning) at IIT Mandi
DRDO Scientist -B
ISRO Scientist-B 2023
BARC RECRUITMENT 2023
Subjects
All categories
General Aptitude
(2.8k)
Engineering Mathematics
(9.7k)
Digital Logic
(3.4k)
Programming and DS
(5.9k)
Algorithms
(4.6k)
Theory of Computation
(6.7k)
Compiler Design
(2.3k)
Operating System
(5.0k)
Databases
(4.6k)
CO and Architecture
(3.8k)
Computer Networks
(4.7k)
Non GATE
(1.4k)
Others
(2.4k)
Admissions
(667)
Exam Queries
(1.0k)
Tier 1 Placement Questions
(17)
Job Queries
(77)
Projects
(9)
Unknown Category
(867)
Recent Blog Comments
Left with 10days, nothing heard back from them,...
I have updated the blog. Thanks for mentioning it.
Mtech(RA) CSE IIT Bombay Project 14 ?
Thanks man @ijnuhb because of u i cleared...
Yes : 720 General
Twitter
WhatsApp
Facebook
Reddit
LinkedIn
Email
Link Copied!
Copy