I'm new to system programming in C.
(我是C语言系统编程的新手。)
Here I'm trying to write a program that changes its PID every (n=2) seconds.
(在这里,我正在尝试编写一个程序,该程序每(n = 2)秒更改其PID。)
But while compiling, I get every time, the same PID. (但是在编译时,我每次都会得到相同的PID。)
The PID never changes. (PID永不更改。)
Does anyone have an idea please ? (请问有人有主意吗?)
Here is my code:
(这是我的代码:)
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int main(){
printf("Programme qui change de PID toutes les deux secondes
");
pid_t fils;
while(1){
printf("I'm %d
",(int)getpid());
sleep(5);
fils = fork();
if(fils < 0){
perror("Fork child
");
exit(1);
}
else if (fils ==0 )
exit(0);
}
return 0;
}
ask by Hajar ELKOUMIKHI translate from so 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…