Menu

#32 Implement exec()

1.0
open
nobody
None
False
2016-11-03
2014-09-22
No

exec() can be implmented in a simplistic kind of way in the library layer by calling spawn() followed by exit(). The net result for the caller is that the new process is left running and the existing one is terminated. The only difference is that the pid will change. Does this matter? Probably not.

Arguably, there's no way for any process under Unix to know for certain what the pid of the process which exec()'d it, and we can't easily pass it from one to the next (unless we pass it explicitly via argv[]), so we can probabyl hide this :-)

Care must be taken in the error path, so that we don't exit() the calling process if the spawn() fails.

Discussion

  • Brian Ruthven

    Brian Ruthven - 2015-01-22

    Also, this will break any parent/child/grandchild relationship, not that any of that is implemented in SpecOS (yet?)

    We could implement the suggestion above, but in-kernel, connecting the child process to the grandparent before killing off the parent in the middle.

     
  • Brian Ruthven

    Brian Ruthven - 2016-10-25

    Alternatively, given there is no direct parent/child link between processes, we could tweak proc_create to take a target pid, and rather than calling proc_table_insert() to get a new pid, simply use the target pid. The exec() syscall handler would therefore effectively become "if (proc_create(target_pid) == -1) { return (errno); } else { proc_exit(); }"

    There would be a brief time when both processes would have the same pid, but the window would be very small.

     
  • Brian Ruthven

    Brian Ruthven - 2016-11-03

    On the other hand, with spawn() available, I haven't had a need for either fork() or exec(), so it's possible I could just ignore exec() completely.

     

Log in to post a comment.