ProvaPratica 2013.02.15

From Sistemi Operativi
Revision as of 03:17, 12 December 2013 by Edu san (talk | contribs) (Created page with "Esercizio 1 del 2013.02.15 <syntaxhighlight lang="C"> /* * Prova Pratica di Lab SO 2013.02.15 * http://www.cs.unibo.it/~renzo/so/pratiche/2013.02.15.pdf * Es.1 * Eduardo S...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Esercizio 1 del 2013.02.15

/*
 *	Prova Pratica di Lab SO 2013.02.15
 *	http://www.cs.unibo.it/~renzo/so/pratiche/2013.02.15.pdf
 *	Es.1
 *	Eduardo Santarelli
 */
#include <stdio.h>
#include <errno.h>
#include <dirent.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>

/*	Selector function, called by scandir. Only selects
 *	palindrome file names. Discards implied directories.
 */
int dir_is_pal(const struct dirent* dir){
  int i,j;

	//discard implied dirs
	if(dir->d_name[0]=='.' && strlen(dir->d_name)<3)
		return 0;

  for(i=0, j=strlen(dir->d_name)-1; i<j; i++, j--)
    if(dir->d_name[i]!=dir->d_name[j])
      return 0;

  return 1;
}

int main(int argc, char** argv){
	struct dirent** entry;
	int i, items;
	pid_t pid;

	items=scandir("./", &entry, dir_is_pal, alphasort);

	for(i=0; i<items; i++){
		int status;
	  if((pid=fork())) ; //do nothing
  	else
		execl(entry[i]->d_name, entry[i]->d_name, (char*)0);
	}

	return 0;
}

-Eduardo