你头脑中的问题答案:是的,这是针对学校的.不,我不能使用线程.是的,我寻找答案,有些人说"是",其他人则说"不".我也正在检查我的教授,因为如果其他人要对其进行评分并且他们要求"修复",我不想不公平地失去分数.
有了这样说......在Linux系统上考虑这个简单的c程序.我malloc的东西,然后叉.我把我的项目归结为确切的问题:
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/wait.h>
#include <sys/types.h>
int main( void )
{
char * args [] = { "someinvalidcommand", NULL };
// malloc before the fork (happens in parent process)
char * something = (char *)malloc(sizeof(char));
pid_t child_pid = fork();
// are there now two things that need to be freed:
// one for each process?
if(child_pid == 0) // child process
{
//free(something); // is this needed?
// execvp (it won't return if succeeded) …Run Code Online (Sandbox Code Playgroud)