在本章中,我们将熟悉进程组,会话和作业控制。
进程组(Process Groups ) - 进程组是一个或多个进程的集合,一个进程组由一个或多个共享相同进程组标识符(PGID)的进程组成。
会话(Sessions) - 它是各种进程组的集合。
作业控制(Job Control) - 这允许Shell程序用户同时执行多个命令(或作业),其中一个在前台,而其余所有在后台。
让我们借助使用Shell(BASH)的示例程序来理解这一点。
Shell脚本(以BASH格式)执行名为basic_commands.sh的基本命令(date,echo,sleep和cal)
Shell脚本(在BASH中)执行基本命令(ps,echo)
#!/bin/bash #basic_commands.sh date echo "Now sleeping for 250 seconds, so that testing job control functionality is smooth" sleep 250 cal
#!/bin/bash #process_status.sh ps echo "Now sleeping for 200 seconds, so that testing job control functionality is smooth" sleep 200 ps
使用chmod命令授予文件执行权限,默认情况下,普通文件将仅获得读写权限,而没有执行权限。
要停止当前正在运行的进程,您需要输入CTRL + Z。
可以使用" fg"命令在前台恢复作业,如果需要,要在后台恢复作业,请使用" bg"命令,也可以使用CTRL + C或kill命令终止该进程。
检查以下输出,该输出演示了停止作业,将作业从前台移至后台,反之亦然,终止作业等。
chmod u+x basic_commands.sh chmod u+x process_status.sh ./basic_commands.sh Wed Jul 5 18:30:27 IST 2017 Now sleeping for 250 seconds, so that testing job control functionality is smooth ^Z [1]+ Stopped ./basic_commands.sh ./process_status.sh PID TTY TIME CMD 2295 pts/1 00:00:00 bash 4222 pts/1 00:00:00 basic_commands. 4224 pts/1 00:00:00 sleep 4225 pts/1 00:00:00 process_status. 4226 pts/1 00:00:00 ps Now sleeping for 200 seconds, so that testing job control functionality is smooth ^Z [2]+ Stopped ./process_status.sh jobs [1]- Stopped ./basic_commands.sh [2]+ Stopped ./process_status.sh fg ./process_status.sh ^Z [2]+ Stopped ./process_status.sh fg %2 ./process_status.sh ^Z [2]+ Stopped ./process_status.sh fg %1 ./basic_commands.sh ^Z [1]+ Stopped ./basic_commands.sh jobs [1]+ Stopped ./basic_commands.sh [2]- Stopped ./process_status.sh bg %2 [2]- ./process_status.sh & fg ./basic_commands.sh ^Z [1]+ Stopped ./basic_commands.sh jobs [1]+ Stopped ./basic_commands.sh [2]- Running ./process_status.sh & fg %2 ./process_status.sh ^Z [2]+ Stopped ./process_status.sh jobs [1]- Stopped ./basic_commands.sh [2]+ Stopped ./process_status.sh kill %1 %2 [1]- Stopped ./basic_commands.sh [2]+ Stopped ./process_status.sh [1]- Terminated ./basic_commands.sh [2]+ Terminated ./process_status.sh
进程 - 组&会话&控制 - 无涯教程网无涯教程网提供在本章中,我们将熟悉进程组,会话和作业控制。进程组(Process Groups ) - 进程组...https://www.learnfk.com/process/inter-process-communication-process-groups-sessions-job-control.html