exvp usage while the program is running
i am trying to write a c a program that takes a command with some parameters from the command line and somewhere inside the program try to
execute them with and without the parameters using exepv but i'm having problems with the syntax.I tried to use a null pointer but its not working.
can u help me?
int main(int argc ,char *argv[])
{
int fd[2];
char mesage [100];
int i;
int n = atoi(argv[1]); //changes the string to number;
int pid1, pid2, pd, status;
char a[1];
//a = NULL;
char command[50];
for (i = 2; i<argc; i++)
{
strcat(command,argv[i]); //copies the commands into one array;
}
while (c)
{
printf("*");
sleep(1);
signal(SIGINT,handler);
}
signal(SIGALARM,killer)
alarm(n);
exevp ("prstat",a); //father executes the prstat
if (pipe(fd)==-1)
{ /*create a pipe*/
perror("pipe");
exit(1);
}
/*-------------------------------------------------childs*/
if ((pid1 = fork())== -1)
{
perror("fork");
exit(1);
}
if ( pid1 == 0 ) //ch1 writer;
{
// pd1 = getpid();
close(fd[READ];
write(fd[WRITE], argv[2], sizeof(argv[2])+1); //it writes the command
close(fd[WRITE]);
exevp(command,a);
}
if ((pid2 = fork()) == -1)
{
//pd2 = getpid();
perror("fork");
exit(-1);
}
if (pid2 == 0)
{
close(fd[WRITE]);
reader = read(fd[READ]), mesage,sizeof(mesage)); //have reads the mesage wich is the command
exevp(mesage,a);
close (fd[READ]);
}
/*-------------------------------------------------------*/
pd=wait(&status) //verify the end of one child
printf("my childs pid is %d \n",pd);
pd=wait(&status) //verify the end of other child
printf("my other childs pid is %d \n",pd);
while (end) //when ends the alarm all ends
pause()
exit (0);
}
|