[英]Shell Script - Fork A Process
我已经获得了使程序显示类似于UI menu
任务,并具有诸如ls
who
和top
类的简单任务,然后将Shell脚本的过程分叉到子进程,然后从新创建的子进程运行后续命令。 但是我不了解C ++,而是想使用Shell脚本。 到目前为止,我的代码如下:
#!/bin/bash
trap '' 2 #trapping the CTRL + C command so users are forced to use number 4 to stop.
while true #while statement for the return function
do
clear #clears the screen so it doesn't look messy when looping
echo "=============================================="
echo "| Outside The CPU Shell Script |"
echo "=============================================="
echo "| Enter 1 for Who |"
echo "| Enter 2 for Ls |" #basic echos to show the menu
echo "| Enter 3 for Top |"
echo "| Enter 4 to exit |"
echo "=============================================="
echo -e "\n" #returns a new line
echo -e "Enter your selection \c |" #prompts to select while suppressing output
read answer #reads input and stores value in variable named answer
case "$answer" in # a case statement (like if/elif statement) using variable answer
1) who ;; #actual command that is used
2) ls ;;
3) top ;;
4) exit ;;
esac #ending statement for the case
echo -e "Enter return to continue \c" #the return statement to bring back to main menu
read input #read enter and store in variable input
done
当该脚本称为fork时,我将如何进行处理,然后控制它创建的子进程?
谢谢,
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.