I am writing a C program in linux.
I have created a process and forking it to create a child. I want to run another program in this child so I am using execlp. But, this program must run in an independent window.
if ( (execlp("xterm","xterm","-e","./Child1", "127.0.0.1", (char *) 0)) < 0) {
printf("Failed to Start the Echo Client. Exiting application.");
return 1;
}
Child1.c is a simple program which is in the same directory as my current file.
On execution the code runs fine with the xterm window coming up but I get an error "xterm: Can't execvp: No file or directory"
Can you please suggest me a resolution?
Your system might not have an
xterminstalled (or the user has a wrongPATH). You could test the existence of/usr/bin/xterm(with e.g. theaccesssyscall), or use something else. For example, many Debian or Ubuntu distributions have ax-terminal-emulator(which is usually a symlink to some precise program) which you could use instead ofxterm.If
xtermfires up, then your program./Child1does not exist, you should test its existence (withaccess) before. If you only have a source code./Child1.cyou should have compiled it before (perhaps by running asystem("gcc -Wall Child1.c -o Child1")before and testing that it has compiled successfully, i.e. test thatsystemreturns 0 and that theChild1file exists and is executable).You should take time to read the xterm(1) man page.