C programming - System Programming - Lecture Notes | CS 241, Study notes of Computer Science

Material Type: Notes; Professor: Gupta; Class: System Programming; Subject: Computer Science; University: University of Illinois - Urbana-Champaign; Term: Fall 2008;

Typology: Study notes

Pre 2010

Uploaded on 03/10/2009

koofers-user-5qe
koofers-user-5qe 🇺🇸

7 documents

1 / 5

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
I. C Programming
1. What is the * operator? What does it do?
2. What is the & operator? What does it do?
3. What’s the difference between char c[80] and char *c?
…what about when they’re used in sizeof()?
4. What do common C functions do? How are they called?
String Functions: strcpy(), strlen(), strcmp()
Memory Functions: malloc(), remalloc(), free()
I/O Functions: printf(), fgets(), fgetc(), read(), write(), fread(), fwrite()
Thread-related Functions: pthread_create(), pthread_join(), pthread_detacth()
Semaphore-related Functions: sem_init(), sem_destroy(), sem_post(), sem_wait()
… and others.
5. What is NULL?
6. Understand how to trace and write pointer code.
7. What’s the difference between a stack and a heap variable? What about global and static
variables?
II. Operating Systems
1. What is the difference between a function call and a system call?
2. - What is an example of a purely function call? Any string function.
- What is an example of function call that is a thinly wrapped system call? Fork(), fread(), fopen()
- Why does printf() not fit in either category? It only makes a system call when necessary. (i.e.
when it writes to the screen)
3. What is the difference between a process and a thread?
4. How do a user-thread and a kernel-thread differ?
5. What are the different states that a process may be in within in operating system?
6. What is a zombie thread? What is an orphan thread?
7. What are the return values of fork()?
8. What parts of memory are retained when fork() is called?
9. How do you abandon a thread? How do you kill it? How do you wait for it to finish?
10. What does it mean for a function to be thread-safe?
III. Synchronization
1. When is synchronization needed?
2. What is the difference between a semaphore and a mutex? Can you use mutexes in place of a
semaphore?
3. What is a critical section?
4. What is deadlock? What other properties are there in relation to synchronization?
5. How does semaphores and testandset() differ?
6. What are algorithms learned in class to deal with synchronization?
7. How do you define a POSIX semaphore in C? What are the two main function calls to use it? How
to you clean up the memory associated with a semaphore?
IV. Scheduling
1. Why do processes need to be scheduled?
2. How do you schedule with a FIFO policy? SJF? Round robin?
3. What does it mean for a scheduling algorithm to be preemptive?
4. How does bounded wait apply to scheduling? What is starvation? What is the convey effect?
pf3
pf4
pf5

Partial preview of the text

Download C programming - System Programming - Lecture Notes | CS 241 and more Study notes Computer Science in PDF only on Docsity!

I. C Programming

  1. What is the * operator? What does it do?
  2. What is the & operator? What does it do?
  3. What’s the difference between char c[80] and char *c? …what about when they’re used in sizeof()?
  4. What do common C functions do? How are they called? String Functions: strcpy(), strlen(), strcmp() Memory Functions: malloc(), remalloc(), free() I/O Functions: printf(), fgets(), fgetc(), read(), write(), fread(), fwrite() Thread-related Functions: pthread_create(), pthread_join(), pthread_detacth() Semaphore-related Functions: sem_init(), sem_destroy(), sem_post(), sem_wait() … and others.
  5. What is NULL?
  6. Understand how to trace and write pointer code.
  7. What’s the difference between a stack and a heap variable? What about global and static variables? II. Operating Systems
  8. What is the difference between a function call and a system call?
    • What is an example of a purely function call? Any string function.
  • What is an example of function call that is a thinly wrapped system call? Fork(), fread(), fopen()
  • Why does printf() not fit in either category? It only makes a system call when necessary. (i.e. when it writes to the screen)
  1. What is the difference between a process and a thread?
  2. How do a user-thread and a kernel-thread differ?
  3. What are the different states that a process may be in within in operating system?
  4. What is a zombie thread? What is an orphan thread?
  5. What are the return values of fork()?
  6. What parts of memory are retained when fork() is called?
  7. How do you abandon a thread? How do you kill it? How do you wait for it to finish?
  8. What does it mean for a function to be thread-safe? III. Synchronization
  9. When is synchronization needed?
  10. What is the difference between a semaphore and a mutex? Can you use mutexes in place of a semaphore?
  11. What is a critical section?
  12. What is deadlock? What other properties are there in relation to synchronization?
  13. How does semaphores and testandset() differ?
  14. What are algorithms learned in class to deal with synchronization?
  15. How do you define a POSIX semaphore in C? What are the two main function calls to use it? How to you clean up the memory associated with a semaphore? IV. Scheduling
  16. Why do processes need to be scheduled?
  17. How do you schedule with a FIFO policy? SJF? Round robin?
  18. What does it mean for a scheduling algorithm to be preemptive?
  19. How does bounded wait apply to scheduling? What is starvation? What is the convey effect?
  1. What is response time? Turn-around time? What other metrics do we use? Section I: Processes and Threads 1.1) Consider the following code: 01: 02: 03: 04: int i; for (i = 0; i < 5; i++) fork(); printf(“Count me!”); How many different types does the text “Count me!” become printed to stdout? Answer: (^) 32 times 1.2) Answer the following questions with either “process”/”processes”, “user-level threads”/”user-level thread”, or “kernel-level threads”/”kernel-level thread”: A single [a] user-level threads requesting I/O will block all other [b] user-level thread in the same [c] process from executing. A [d] user-level thread doesn’t require a context switch when switching tasks. A [e] process cannot access the heap variables of another [e]. 1.3) Explain the following POSIX thread calls: [a] : pthread_create() Function used to create a thread, with attributes within a process. Return upon success zero, otherwise error number to indicate the error [b] : pthread_join() One thread wants to wait for another thread to finish NOTE: pthread_detach: allows a thread to finish without joining it [c] : pthread_exit() You can call pthread_exit if you know the Thread ID, you will terminate a specific thread.

Waiting Time: Total time a process is in the Ready queue CPU Utilization: CPU_cycles/total_CPU_cycles_per_unit Throughput: # processes completing execution per unit time

Section III: Memory Allocation 3.1) Consider the following code: 01: 02: 03: 04: 05: 06: 07: 08: 09: 10: 11: 12: #include <stdio.h> int main(int argc, char** argv) { int* a = malloc(sizeof(int)); void* b = &a; void* c = a; void* d = *a; return 0; } Let us assume that the stack memory starts at the address 1000 and counts up while the heap memory starts at the address 2000 and counts down. Assuming no padding or extra memory allocations has been done before reaching Line #5: Where is the variable stored in memory? What is the memory address that the variable is pointing to? a (^) 1000 2000 b (^) 1004 1000 c (^) 1008 2000 d (^) 1012 undefined 3.2) Consider the following structure: 01 02 03 04 05 06 07 typedef struct __myStruct { int myValue, yourValue; char myChar; char *yourString; double yourDouble; } myStruct; The following assumptions are given: A A A A A sizeof(char) = 1 sizeof(int) = 4 sizeof(float) = 4 sizeof(void) = 4 sizeof(double) = 8 What is the return value of sizeof(myStruct)? Answer: 4+4+4+4+1=