系统编程第一天练习题
- fork()用法
- atexit(),exit()
- 多个进程的运用
- 子进程退出值的获取
- excel族函数的运用
练习:
1、创建一个子进程, 在子进程里面每隔1s打印一个数字,打印1~10;父进程每隔1s打印一个字母,打印26个小写字母
#include <stdio.h>
#include <unistd.h>
int main(int argc, char const *argv[])
{
pid_t x;
x = fork();
//子进程
if(x==0)
{
int i = 1;
while(1)
{
printf("%d\n",i);
i++;
sleep(1);
if(i>=11)
{
i = 1;
}
}
}
if(x>0)
{
int i = 97;
while(1)
{
printf("%c\n",i);
i++;
sleep(1);
if(i>=123)
{
i = 97;
}
}
}
return 0;
}
2、 在进程退出时,把全局变量int