Issue
How can I implement chmod command on file by using exec? I would appreciate if anyone can provide me a code.
id='dv4'>
Solution
try this: http://support.sas.com/documentation/onlinedoc/sasc/doc/lr2/execve.htm also see: http://linux.about.com/library/cmd/blcmdl3_execvp.htm
#include <sys/types.h>
#include <unistd.h>
#include <stdio.h>
main()
{
pid_t pid;
char *parmList[] = {"/bin/chmod", "0700", "/home/op/biaoaai/bead",NULL};
if ((pid = fork()) ==-1) //fork failed
perror("fork error");
else if (pid == 0) { //child (pid==0 if child)
execvp("chmod", parmList);
printf("Return not expected. Must be an execve error.n");
} else { //parent (pid==child process)
//parent specific code goes here
}
}
Edit: I never actually compiled... updated with users working paramList.
Answered By - user295190 Answer Checked By - Terry (WPSolving Volunteer)