It's UWAweek 38 (2nd semester, week 8)

help2002

This forum is provided to promote discussion amongst students enrolled in CITS2002 .
Please consider offering answers and suggestions to help other students! And if you fix a problem by following a suggestion here, it would be great if other interested students could see a short "Great, fixed it!"  followup message.
Displaying the 12 articles in this topic
Showing 12 of 1189 articles.
Currently -1 other people reading this forum.


 UWA week 34 (2nd semester, week 5) ↓
SVG not supported

Login to reply

👍?
helpful
6:30pm Tue 25th Aug, ANONYMOUS

Does anyone know the answer to question 20 of mid sem? I believe it's c. because the fork() function duplicates twice resulting in 4 processes. But I'm uneasy with the overall syntax. Thank you!!


SVG not supported

Login to reply

👍?
helpful
6:40pm Tue 25th Aug, ANONYMOUS

fork call is in the lectures after the test, does this mean we can expect it to not be in the test?


SVG not supported

Login to reply

👍?
helpful
1:30am Wed 26th Aug, ANONYMOUS

ANONYMOUS wrote:
> Does anyone know the answer to question 20 of mid sem? > I believe it's c. because the fork() function duplicates > twice resulting in 4 processes. But I'm uneasy with the overall > syntax. > Thank you!!
I don't have the question in front of me at the moment, but if I recall it was something like fork(); fork(); printf("hello world\n"); In this case, "hello world" will be printed 4 times, on 4 separate lines.


SVG not supported

Login to reply

👍?
helpful
4:25am Wed 26th Aug, Christopher M.

ANONYMOUS wrote:
> fork call is in the lectures after the test, does this mean we can expect it to not > be in the test?
Yes, we will talk more about fork() and process creation after the test, but we have 'discussed' its role, in lectures, sufficiently to answer this and similar questions.


 UWA week 35 (2nd semester, week 6) ↓
SVG not supported

Login to reply

👍?
helpful
1:42pm Thu 27th Aug, Jake N.

Try running the code given! #include <stdio.h> #include <stdlib.h> #include <unistd.h> void function(void) { fork(); fork(); printf("Hello world\n"); } int main(int argc, char *argv[]) { function(); exit(EXIT_SUCCESS); } Should help clarify it!


SVG not supported

Login to reply

👍?
helpful
4:31pm Sat 29th Aug, Benjamin L.

"Jake Nelson" <20*5*9*8@s*u*e*t*u*a*e*u*a*> wrote:
> Try running the code given! > > #include <stdio.h> > #include <stdlib.h> > #include <unistd.h> > > void function(void) > { > fork(); > fork(); > printf("Hello world\n"); > } > > int main(int argc, char *argv[]) > { > function(); > exit(EXIT_SUCCESS); > } > > Should help clarify it!
Hi, I compiled my code using the following syntax: void function(void) { fork(); fork(); printf("hello world\n"); } int main(void) { function(); return 0; } And, as expected it prints "hello world" 4 times on seperate lines; However, the solutions to the mid-semester test state that 'D' is the right answer. Which says "The form of the output cannot be determined from the above code", is this because a different operating system may give a different result, or is this a typo in the solutions?


SVG not supported

Login to reply

👍?
helpful
5:38pm Sat 29th Aug, ANONYMOUS

I thought that C language is Operating System independent, meaning that it can be compiled on most systems. I don't know, please let me know if I'm going wrong. I read it in the book that is prescribed on this website.


SVG not supported

Login to reply

👍?
helpful
7:56pm Sat 29th Aug, David C.

ANONYMOUS wrote:
> I thought that C language is Operating System independent, meaning that it can be > compiled on most systems. I don't know, please let me know if I'm going wrong. I read it > in the book that is prescribed on this website.
Yeah not always as the Microsoft MSDN states. "One of the largest areas of difference is in the process model. UNIX has fork; Win32 does not" Got me too even after I wrote a test program it failed to compile on a windows machine ( but it worked on Linux). I said C. ( 4x hello) I guess the lesson here is to read the actual question. If it said "What would the output be under Linux" then it would be a different story. https://msdn.microsoft.com/en-us/library/y23kc048.aspx


SVG not supported

Login to reply

👍?
helpful
5:31pm Sun 30th Aug, Christopher M.

"Benjamin Lopas" <19*2*9*1@s*u*e*t*u*a*e*u*a*> wrote:
> And, as expected it prints "hello world" 4 times on seperate lines; However, > the solutions to the mid-semester test state that 'D' is the right answer. Which > says "The form of the output cannot be determined from the above code", is this > because a different operating system may give a different result, or is this > a typo in the solutions?
What actually happens depends on the interleaving/scheduling of the 4 running processes, whether they buffer their output (and maybe some external factors, but that would be too pedantic to ask about). In short, from the short bit of code, we can't tell what may happen.


SVG not supported

Login to reply

👍?
helpful
5:36pm Sun 30th Aug, Christopher M.

ANONYMOUS wrote:
> I thought that C language is Operating System independent, meaning that it can be > compiled on most systems. I don't know, please let me know if I'm going wrong. I read it > in the book that is prescribed on this website.
Yes, C is OS independent, meaning that the language makes no strong demands of the OS on which its programs run. But that's not related to the question - fork() is not a function defined as part of the standard C library, it's a system-call (function) provided by some OSs. Similarly, a C program, compiled and running on Windows, may be able to call a function named Start_Microsoft_Office(), but that's unrelated to whether or not C is OS independent.


SVG not supported

Login to reply

👍?
helpful
5:38pm Sun 30th Aug, Christopher M.

"David Chinnery" <21*4*7*1@s*u*e*t*u*a*e*u*a*> wrote:
> Got me too even after I wrote a test program it failed to compile on a windows machine ( but it > worked on Linux). I said C. ( 4x hello) I guess the lesson here is to read the actual question. > If it said "What would the output be under Linux" then it would be a different story.
No, don't try and read too much into the question - it's not trying to be tricky. The question asks "If the above code executes successfully....", so the code must have already compiled and linked successfully to get that far.


SVG not supported

Login to reply

👍?
helpful
12:12pm Tue 1st Sep, Benjamin J.

"Christopher McDonald" <ch*i*.*c*o*a*d@u*a*e*u*a*> wrote:
> "David Chinnery" <21*4*7*1@s*u*e*t*u*a*e*u*a*> wrote: > > > Got me too even after I wrote a test program it failed to compile on a windows machine ( but it > > worked on Linux). I said C. ( 4x hello) I guess the lesson here is to read the actual question. > > If it said "What would the output be under Linux" then it would be a different story. > > No, don't try and read too much into the question - it's not trying to be tricky. > > The question asks "If the above code executes successfully....", > so the code must have already compiled and linked successfully to get that far.
But if the questions asks "If the above code executes successfully..." and we can therefore assume that it compiled fine - why wouldn't we know sorry? Surely the OS supports the call and therefore it would be four?

The University of Western Australia

Computer Science and Software Engineering

CRICOS Code: 00126G
Written by [email protected]
Powered by history
Feedback always welcome - it makes our software better!
Last modified  8:08AM Aug 25 2024
Privacy policy