Exemple #1
0
int main(int argc, char** argv)
{
    int serpid;

    serpid = 0;
    if(argc >= 3)
    {
        if((serpid = atoi(argv[1])) > 0)
        {
            my_str("--CLIPID-->");
            my_int(getpid());
            my_str("<--\n");

            signal(SIGUSR1, ack);
            signal(SIGALRM, omg);
            sendpid(serpid, getpid());
            if(!gl_ack)
            {
                alarm(5);
                pause();
            }
            alarm(0);
            gl_ack = 0;

            my_str("--SENDING STRING-->");
            my_str("<--\n");

            sendstring(serpid, my_vect2str(&argv[2]));
            gl_ack = 0;

            my_str("--FINISHED SENDING STRING-->");
            my_str("<--\n");
        }
    }

    return 0;
}
Exemple #2
0
/**
 * Begins program execution
 * @param  argc The number of command line arguments
 * @param  argv An array of C strings containing each command line argument
 * @return The exit code
 */
int main(int argc, char** argv)
{
	/* Check the command line arguments */
	if (argc < 2)
	{
		fprintf(stderr, "USAGE: %s <FILE NAME>\n", argv[0]);
		exit(-1);
	}
		
	/* Install a signal handler for the SIGUSR2 signal */
	if (signal(SIGUSR2, usr2Signal) == SIG_ERR)
	{
		perror("signal");
		exit(-1);
	}

	/* Initialize */
	init(shmid, sharedMemPtr);
	
	/* Get the pid of the receiver */
	rpid = recvpid();

	/* Send the pid of this process */
	sendpid();

	/* Send the name of the file */
	sendFileName(argv[1]);

	/* Send the file */
	fprintf(stderr, "The number of bytes sent is %lu\n", sendFile(argv[1]));
	
	/* Cleanup */
	cleanUp(shmid, sharedMemPtr);
		
	return 0;
}