#include <sys/types.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <stdio.h>
#include <signal.h>

#define PS 3

void error(char *);

int main(int argc, char **argv)
{
	if(argc!=1)
	{ 
    		printf("edwses latos orismata\n");
		exit(0);
	}
	
	//int sd = socket(AF_UNIX, SOCK_STREAM, 0);
	int servlen,new_sd;
	struct sockaddr_un serv_addr;

	bzero((char *)&serv_addr,sizeof(serv_addr));
	 
	serv_addr.sun_family = AF_UNIX;

	strcpy(serv_addr.sun_path, "mysock");
	
	servlen = strlen(serv_addr.sun_path) + sizeof(serv_addr.sun_family);
	
	if ((new_sd = socket(AF_UNIX, SOCK_STREAM,0)) < 0)
	{	error("sfalma sth dhmioyrgia toy socket");	}

	if (connect(new_sd, (struct sockaddr *) &serv_addr, servlen) < 0)
       	{	error("sfalma sundesis toy client me ton server");	}
	//connect(sd,(struct sockaddr*)&srv , sizeof(srv));
	
	int op = 3;

	write(new_sd,&op,sizeof(int));	//stelnw ston server tin praxi poy telw na kanei (dhl exec)
	int count;
	read(new_sd, &count, sizeof(int));	//diabazw apo ayto poy moy stelnei o server (dhl tis diergasies poy ekteloyntai)
	int i = 0;
	for (i = 0; i<count; i++)
	{
		int size;
		read(new_sd,&size, sizeof(int));
		char *name = (char*) malloc (size);
		read(new_sd, name, size);
		int pid;
		read (new_sd, &pid, sizeof(int));
		int psstatus;
		read (new_sd, &psstatus, sizeof(int));
		printf("telos emfanishs\n");
	}
	return 0;	
}



void error(char *msg)
{
    perror(msg);
    exit(0);
}
