Linux进程相关命令
进程前后台切换
编写测试demo
#include<iostream>
#include<string>
#include<thread>
#include<chrono>
using namespace std;
void toast(int wait_time = 10,string toast="None")
{
while(1)
{
this_thread::sleep_for(chrono::seconds(wait_time));
cout << toast << endl;
}
}
int main()
{
string tip1 = "tip1 tip1 tip1";
string tip2 = "tip2 tip2 tip2";
thread tt1(toast,3,tip1);
thread tt2(toast,5,tip2);
tt1.join();
tt2.join();
}
编译链接 生成可执行文件
程序切换至后台执行
方法一 在可执行程序的末尾使用&
方法二 ctrl+z 将程序放到后台执行并暂停
使用jobs查看后台运行的进程
使用fg将后台进程调回前台
使用bg让后台进程继续执行
PS
ps -a 列出所有运行中/激活进程
ps -a (有程序在后台运行时)
ps -aux(显示进程信息,包括无终端的(x)和针对用户(u)的进程)
使用ps -aux | grep “string” 查找需要的进程
pstree
显示进程关系 不指定pid默认为1init
top 监视不同进程使用的资源
nice
-20 - 19 值越低 优先级越高
不使用nice的情况