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, 2023
470
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, 2023
by
vikranty2j
470
views
answer
comment
Follow
share this
share
3 Comments
by
chinmay_rajpurohit
commented
Mar 20, 2023
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 21, 2023
reply
Follow
share this
I am getting this expression.
2^(n+1)-2
0
0
by
chinmay_rajpurohit
commented
Mar 23, 2023
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, 2023
by
kickassakash
comment
Follow
share this
1 comment
by
vikranty2j
commented
Mar 21, 2023
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
0
votes
0
votes
1
answer
1
Erwin Smith
asked
in
Operating System
Apr 11, 2023
761
views
Fork() system call doubt
void main() { int n = 1; if(fork()==0) { n = n<<1; printf(“%d, “, n); n = n <<1; } if(fork()==0) n=n+700; printf(“%d, “,n); } Which of the following output is not possible? 2,4,1,701,704 1,2,4,704,701 2,704,4,701,1 1,704,2,4,701
Erwin Smith
asked
in
Operating System
Apr 11, 2023
by
Erwin Smith
761
views
fork-system-call
operating-system
programming-in-c
3
votes
3
votes
1
answer
2
indrajeet
asked
in
Operating System
Nov 20, 2016
1,882
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.9k
views
operating-system
fork-system-call
programming-in-c
2
votes
2
votes
3
answers
3
Philosophical_Virus
asked
in
Operating System
Dec 10, 2023
769
views
System Call FORK()
Int main () { fork(); printf("a"); fork(); printf("b"); return 0; } How many distinct outputs are possible of above code? And also give outputs
Philosophical_Virus
asked
in
Operating System
Dec 10, 2023
by
Philosophical_Virus
769
views
operating-system
fork-system-call
1
vote
1
vote
0
answers
4
Souvik33
asked
in
Operating System
Nov 28, 2022
768
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
768
views
operating-system
fork-system-call
unix
process-and-threads
threads
multiple-selects
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
Post GATE 2024 Guidance [Counseling tips and resources]
GATE CSE 2024 Result Responses
[Project Contest] Pytorch backend support for MLCommons Cpp Inference implementation
Participating in MLCommons Inference v4.0 submission (deadline is February 23 12pm IST)
IIITH PGEE 2024 Test Series by GO Classes
Subjects
All categories
General Aptitude
(3.5k)
Engineering Mathematics
(10.4k)
Digital Logic
(3.6k)
Programming and DS
(6.2k)
Algorithms
(4.8k)
Theory of Computation
(6.9k)
Compiler Design
(2.5k)
Operating System
(5.2k)
Databases
(4.8k)
CO and Architecture
(4.0k)
Computer Networks
(4.9k)
Artificial Intelligence
(79)
Machine Learning
(48)
Data Mining and Warehousing
(25)
Non GATE
(1.4k)
Others
(2.7k)
Admissions
(684)
Exam Queries
(1.6k)
Tier 1 Placement Questions
(17)
Job Queries
(80)
Projects
(11)
Unknown Category
(870)
64.3k
questions
77.9k
answers
244k
comments
80.0k
users
Recent Blog Comments
category ?
Hi @Arjun sir, I have obtained a score of 591 in ...
download here
Can you please tell about IIT-H mtech CSE self...
Please add your admission queries here:...
Twitter
WhatsApp
Facebook
Reddit
LinkedIn
Email
Link Copied!
Copy