Ejemplo n.º 1
0
/*
  A function that given a process id REMOVE ALL files the specified
  process have in the list.
*/
void flist_remove_process(struct thread* t)
{
  if (t == NULL) return;


  map_remove_if(&(t->open_files), always_true, 0);

}
Ejemplo n.º 2
0
void plist_remove_process(struct map* m , key_t k, bool force_remove)
{
  lock_acquire(&plist_lock);
  struct process* p = map_find(m, k);
  if(p != NULL)
  {
    p->is_alive = 0;
    p->parent_dead = force_remove;
    map_remove_if(m, (void*) &flag_child, k);
  }
  lock_release(&plist_lock);
}
Ejemplo n.º 3
0
int main()
{
  struct map container;
  char input_buffer[10];
  char* obj;
  int id;
  int i;

  map_init(&container);

  /* remember to try to insert more values than you map can hold */
  printf("Insert values: ");
  for ( i = 0; i < LOOPS; ++i)
  {
    /* insecure, scanf may overflow the input buffer array *
     * very serious, but we ignore it in this test program */
    scanf("%s", input_buffer);
    
    /*! allocates a copy of the input and inserts in map */
    obj = my_strdup(input_buffer);
    id = map_insert(&container, obj);
  }

  /* remember to test with invalid keys (like 4711, or -1) */
  for ( i = 0; i < LOOPS; ++i)
  {
    printf("Enter id to find value for: ");
    scanf("%d", &id);

    /*! find the value for a key in the map */
    obj = map_find(&container, id);

    /*! if it was found, display it */
YOUR CODE
  
    /* since we leave the value in the map we may use it again and
     * should not free the memory */
  }

  /* remember to test with invalid keys (like 4711, or -1) */
  for ( i = 0; i < LOOPS; ++i)
  {
    printf("Enter id to remove value for: ");
    scanf("%d", &id);
    
    /*! find and remove a value for a key in the map */
    obj = map_remove(&container, id);

    /*! if it was found, display it */
YOUR CODE
    /* since we removed the value from the map we will never use it again and
     * must properly free the memory (if it was allocated) */
  }

  /*! print all strings representing an integer less than 5 */
  printf("Will now display all values less than N. Choose N: ");
  scanf("%d", &i);
  map_for_each(&container, print_less, 5);
  
  /*! free all remaining memory and remove from map */
  map_remove_if(&container, do_free, 0);
  
  return 0;
}