Linux 进程与进程间通信全解析
1. 进程相关示例与应用
在 Linux 环境中,进程是构建各类应用的基础。下面我们先来看一个使用waitpid函数的示例:
program waitpidExample; {$APPTYPE CONSOLE} uses Libc; var ClonedProcess: integer; ChildStatus: integer; WaitResult: integer; begin writeln('About to fork the process.'); ClonedProcess := fork; if ClonedProcess = 0 then begin //We are the child. Let's sleep on it writeln('The child process is about to sleep'); __sleep(5); writeln('The child process is awake.'); end else if ClonedProcess > 0 then begin writeln('The fork was successful.'); writeln('Waiting on the child process to exit.'); WaitResult := waitpid(ClonedProcess, @ChildStatus, 0); if WaitResult <> –1 then