Review
Consider the code below:
void main() {
int x = 0;
x++;
if (fork()) x++;
x++;
printf("%d\n");
}
None! I Couldn’t think of any
void * thread(void *ptr) { printf("Hello!"); }
void main() {
pthread_t pid1, pid2;
pthread_create(&pid1, NULL, thread, NULL);
pthread_create(&pid2, NULL, thread, NULL);
pthread_join(pid1, NULL);
}
How many times is “Hello!” printed?
Consider the code below:
void main() {
pthread_mutex_t mutex;
pthread_mutex_init(&mutex, NULL);
pthread_cond_t cond;
pthread_cond_init(&cond, NULL);
pthread_cond_broadcast(&cond);
pthread_cond_wait(&cond, &mutex);
}
Describe the result of running this program.
int main() { int *ptr = mmap(NULL, sizeof(int), PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, -1, 0); *ptr = 0; fork(); (*ptr)++; printf("The value is: %d\n", *ptr); }
What all is printed out after the program is executed?void handler(int sig) { printf("foo"); while (1) { } } int main() { signal(SIGINT, handler); while (1) { } return 0; }
If Ctrl+C is pressed 5 times, how many times is “foo” printed out to the screen?
Consider the code below:
void handler(int sig) {
printf("foo\n");
}
int main() {
signal(SIGKILL, handler);
while (1) { }
return 0;
}
Consider the code below:
void handler(int sig) {
printf("foo\n");
}
int main() {
signal(SIGINT, handler);
while (1) { }
return 0;
}