zoukankan      html  css  js  c++  java
  • Forking and Executing the Process

    To create a process using BSD system calls, your process must call the fork system call. The fork call creates a logical copy of your process, then returns the ID of the new process to your process. Both the original process and the new process continue executing from the call to fork; the only difference is that fork returns the ID of the new process to the original process and zero to the new process. (The fork function returns -1 to the original process and sets errno to a specific error value if the new process could not be created.)

    To run a different executable, your process must call the execve system call with a pathname specifying the location of the alternate executable. The execve call replaces the program currently in memory with a different executable file.

    A Mach-O executable file contains a header consisting of a set of load commands. For programs that use shared libraries or frameworks, one of these commands specifies the location of the linker to be used to load the program. If you use Xcode, this is always /usr/lib/dyld, the standard Mac OS X dynamic linker.

    When you call the execve routine, the kernel first loads the specified program file and examines the mach_header structure at the start of the file. The kernel verifies that the file appear to be a valid Mach-O file and interprets the load commands stored in the header. The kernel then loads the dynamic linker specified by the load commands into memory and executes the dynamic linker on the program file.

    The dynamic linker loads all the shared libraries that the main program links against (the dependent libraries) and binds enough of the symbols to start the program. It then calls the entry point function. At build time, the static linker adds the standard entry point function to the main executable file from the object file /usr/lib/crt1.o. This function sets up the runtime environment state for the kernel and calls static initializers for C++ objects, initializes the Objective-C runtime, and then calls the program’s main function. 

    http://www.cs.miami.edu/home/burt/learning/Csc521.091/docs/MachOTopics.pdf

  • 相关阅读:
    C语言常用函数-findfirst()搜索指定磁盘目录里文件函数
    C语言常用函数-getcwd()获取当前工作目录函数
    C语言常用函数目录
    C语言常用函数-_rmdir()建立目录函数
    C语言常用函数-mkdir()建立目录函数
    NX二次开发-UF_DRF_ask_dim_info获得图纸尺寸属于哪个视图和图纸页
    NX二次开发-NXOpenC++属性操作
    VMware虚拟机设置双网卡上网
    FreeCAD二次开发-计算模型是否报错,报错则停止
    NX二次开发-自动将NX标题设置为prt路径
  • 原文地址:https://www.cnblogs.com/feng9exe/p/12457062.html
Copyright © 2011-2022 走看看