工作需要,和大家共同学习总结。(学习的内容为传智播客linux服务器开发二、三部分)
1、环境搭建,利用好win10自带的ubuntu,利用xshell连接。
visual studio中安装linux开发调试环境 :
提示远程需要安装gdb ,安装即可,默认在远程机器的projects目录下:
具体的设置可以修改属性页:
2、知识点:
程序和进程
程序保存在磁盘上,不占用系统资源(cpu、内存、锁、打开的文件)。
进程是抽象的概念,是活跃的程序,是资源分配的最小单位
fork() 父进程返回子进程的id,子进程返回0;
测试代码
#include<unistd.h>
#include<cstdlib>
#include<iostream>
using namespace std;
int main(){
pid_t pid;
cout<<"fork test"<<endl;
pid=fork();
cout<<pid<<endl;
if(pid==-1){
cout<<"fork_error"<<endl;
return 0;
}else if(pid==0){
cout<<"我是子进程"<<endl;
cout<<"getpid(): "<<getpid()<<endl;
cout<<"getppid(): "<<getppid()<<endl;
}else{
cout<<"我是父进程"<<endl;
cout<<"getpid(): "<<getpid()<<endl;
cout<<"getppid(): "<<getppid()<<endl;
cout<<"pid: "<<pid<<endl;
}
while(1){
;
}
return 0;
}