İhsan Doğramacı Bilkent University
CS 342
CS342 Operating Systems Spring 2024 Homework #2
Assigned: Mar 9, 2024.Due date: Mar 17, 2024. Document version: 1.0
Q1. We have the following program. What are the pairs of values printed out by this program?
int a = 300;
int b = 100;
int ret;
int main()
{
re
...[Show More]
|
CS342 Operating Systems Spring 2024 Homework #2
|
|
Assigned: Mar 9, 2024.Due date: Mar 17, 2024. Document version: 1.0
|
Q1. We have the following program. What are the pairs of values printed out by this program?
int a = 300;
int b = 100;
int ret;
int main()
{
ret = fork();
a = a + 10;
if (ret == 0) {
a = a * 2;
b = b + 50;
printf ("%d %d\n", a, b);
if (fork() == 0) {
a = a + 1000;
printf ("%d %d\n", a, b);
exit(0);
}
b = b + 10;
}
else {
a = a + 200;
b = 7 * b;
printf ("%d %d\n", a, b);
b = b + 80;
}
printf ("%d %d\n", a, b);
} Q 2. Consider the following program. What are the values that are printed out by this program?
unsigned long x = 1000;
unsigned long y = 2000;
unsigned long z = 400;
void * func1(void *p)
{
unsigned long x, z;
x = 1300;
y = 3000;
z = *((unsigned long *)p);
z = z + 300;
*((unsigned long *)p) += 500;
printf ("%lu %lu %lu\n", x, y, z);
2
pthread_exit(NULL);
}
int
main()
{
pthread_t tid;
unsigned long a = 5000;
pthread_create (&tid, NULL, &func1, (void *)&a);
pthread_join(tid, NULL);
printf ("%lu %lu %lu\n", x, y, z);
} Q 3. Consider the following program. Find out the triples printed out by this program. What can you say about their order?
[Show Less]
Access Full Document
Instant download after payment
Card Payments
₿
Crypto Accepted