LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 01-24-2010, 05:09 AM   #1
vanpeta
LQ Newbie
 
Registered: Jan 2010
Posts: 1

Rep: Reputation: 0
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);
}
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
maximum memory usage of a program sancho1980 Linux - General 1 08-18-2009 03:01 AM
Running program from terminal with & does nothing, program stops DittoAlex Linux - General 1 10-05-2007 01:35 AM
CPU running at 100% usage while no applications are running mike_morley Linux - Desktop 14 05-17-2007 09:39 PM
Memory usage of openGL program cjp Programming 3 09-09-2004 06:28 AM
Best program for viewing disk usage? Hell255 Linux - Software 11 05-13-2004 10:24 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:38 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration