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

#define KILL 2

void error(char *);

int main(int argc, char **argv)
{
	if(argc!=2)
	{ 
    		printf("edwses lathos orismata. Dwse entoli tis morfis: ./kill [proccess id]\n");
		exit(0);
	}
	
	int pid=atoi(argv[1]);		//metatrepw to alfaritmitiko se int afou to proccess id einai integer
	if(pid<0)
	{	
		error("edvses lathos proccess id (dhl. lathos diergasia gia diagrafi \n");
		exit(1);
	}
	
	//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 = 2;

	write(new_sd,&op,sizeof(int));	//stelnw ston server tin praxi poy telw na kanei (dhl kill)
	printf("pid:%d\n",pid);
	write(new_sd,&pid,sizeof(int));	// auto to stelnw ston server gia na xerei pia diergasia na skotwsei
	
	//int status;
	//write(sd,&status,sizeof(int));	
	//return status;
}


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

