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的情况

在这里插入图片描述
在这里插入图片描述

使用nice的情况

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值