execve使用

注意必须使用waitpid,否则会出现rm的僵尸进程。

DeleteCvsFile(const char *csvfilename)

{
int ac = 0;
char *argv[10];
char *envp[10];
argv[ac++] = "-rf";
argv[ac++] = csvfilename;
argv[ac] = NULL;
envp[0] = NULL;

pid_t pid;
if ((pid = fork_process()) == 0)
{
if (execve("/bin/rm", argv, envp) < 0)
{
ereport(LOG,
(errmsg("could not execute server process "%s".",
"/bin/rm")));
exit(1);
}
}
int ret = waitpid(pid, NULL, 0);
}

原文地址:https://www.cnblogs.com/gelon/p/11799226.html