Advertisement
Guest User

Untitled

a guest
Sep 15th, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.52 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <sys/types.h>
  3. #include <unistd.h>
  4. #include <stdlib.h>
  5. #include <pthread.h>
  6.  
  7. struct t {
  8.  
  9.   void (*a)();
  10.  
  11. }obj;
  12.  
  13.  
  14. void a() {
  15.  
  16.  printf("Hey there\n");
  17.  
  18. }
  19.  
  20. void terminate(struct t *obj) {
  21.  
  22.   free(obj); //free
  23.  
  24. }
  25.  
  26.  
  27.  
  28.  
  29. int main() {
  30.  
  31.  
  32.   struct t *obj;
  33.    
  34.    
  35.   obj = malloc(64);
  36.   obj->a = a;
  37.  
  38.  
  39.  
  40.  
  41.  fork(); //I call fork here so create a child process, after this it should call terminate 2 times or shouldn't?
  42.  
  43. terminate(obj);
  44.  
  45.  
  46.  return 0;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement