/*  This file is part of lsnet. 
    Copyright (C) 2009-2010  Sterling Pickens
    Lsnet is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Lsnet is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with lsnet.  If not, see <http://www.gnu.org/licenses/>.
*/

#include "processes.h"

int processes(void) {
	DIR *dp;
	struct dirent *ep;
	dp = (opendir ("/proc"));
	if(dp == NULL){
		printf("Cannot open directory /proc\n");
		printf("Exiting !\n");
		exit(1);
	}
	int processes = 0;
	while ((ep = readdir (dp))){
		if (ep->d_name[0] == '0' || ep->d_name[0] == '1' || ep->d_name[0] == '2' || ep->d_name[0] == '3' || ep->d_name[0] == '4' || ep->d_name[0] == '5' || ep->d_name[0] == '6' || ep->d_name[0] == '7' || ep->d_name[0] == '8' ||ep->d_name[0] == '9'){  
                       	processes++;
 		}
	}
		(void) closedir (dp);
	return (processes);
}

