understanding requirements for execve and setting environment vars

前端 未结 3 566
遇见更好的自我
遇见更好的自我 2021-02-05 15:58

We are having a lot of trouble interpreting our teacher. We asked for clarification and got the following back from him

  1. For execve, send it a environment you se

3条回答
  •  花落未央
    2021-02-05 16:57

    The code from Jonathan Leffler works great, except if you want to change the PWD (working directory) variable.

    What I did, in order to change the working directory, was to put a chdir(..) before execve(..) and call:

    chdir("/foo/bar"); 
    execve(argv[0], &argv[0], envp);
    

提交回复
热议问题