Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在使用指令启动一个流程
execl("./softCopia","softCopia",NULL);
softCopia 只是一个将整数写入文件的虚拟对象。
我想知道我怎样才能得到这个过程的pid?
由于所有 Unix exec 函数都用新进程替换了正在运行的进程,因此 exec 进程的 PID 与之前的 PID 相同。
因此getpid(),在调用execl.
getpid()
execl
或者,如果你真的想继续运行你的主程序并启动一个新程序,你fork()首先使用。该fork()函数返回负值表示错误,0 表示新的子进程,以及父进程中子进程的 PID。因此,父母可以使用其中一个wait功能,或者只是继续其业务直到以后。
fork()
wait