I want to remove a file present in /tmp, say san.txt
I have two approach, Which one is better and why ?
approach one:
int main(){
int status;
pid_t pid = fork();
if(-1 == pid){
printf("fork() failed");
exit(EXIT_FAILURE);
}else if(pid == 0){
execl("/bin/sh", "sh", "-c", "rm /tmp/san.txt", (char *) NULL);
}else{
printf("[%d]fork with id %d\n",pid);
waitpid(pid,&status,0);
}
return 0;
}
Approach 2:
int main(){
int ret = unlink("/tmp/san.txt");
if ( 0 == ret){
printf("file removed \n");
}
return 0;
}