📄 fork_test.c
字号:
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <time.h>
#include <string.h>
#include <linux/rtc.h>
#include <linux/ioctl.h>
#include <sys/types.h>
#include <sys/wait.h>
int msSleep(int s,long ms)
{
struct timeval tv;
tv.tv_sec = s;
tv.tv_usec = ms;
return select(0, NULL, NULL, NULL, &tv);
}
void PrintTime( const char *s )
{
time_t t;
struct tm *tm;
t=time(NULL); //读系统时间
tm=localtime(&t);
printf(" %s t = %ld tm->tm_sec = %d ",s,t,tm->tm_sec);
}
void fork_child(void)
{
for(;;)
{
printf(" fork_child run. \n");
msSleep(1,0);
}
}
int main ( void )
{
pid_t pc;
pc=fork();
if(pc == 0)
{
fork_child();
exit(0);
}
else if(pc >0)
{
while( 1 )
{
printf("fork_part run. \n");
msSleep(5,0);
}
}
exit(0);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -