Translated:20140813 Command Line Tuesdays--Part Eight.md

This commit is contained in:
GOLinux 2014-08-14 11:18:08 +08:00
parent 22fd112aaf
commit eac56295d3
2 changed files with 67 additions and 69 deletions

View File

@ -1,69 +0,0 @@
Translating by GOLinux ...
Command Line Tuesdays Part Eight
================================================================================
Yo yo, geekos! Here we are, for the final chapter of our CLT hangout. Today, well be talking about job control through which well learn how to control processes running on our computer!
### An Example ###
As we have learned, we can run programs directly from the CLI by simply typing the name of the program. For example, dolphin. If we type:
dolphin
…dolphin, the file manager, opens. If you look at the terminal while this process is opened, you can not access the command prompt and you can not write a new command inside the same window. If you terminate dolphin, the prompt reappears and you can type a new command into the shell. Now, how can we run a program from CLI, while also having our prompt available for further command issuing.
dolphin &
…and you have your dolphin file manager running in background, with the terminal free to type another command you need.
Now imagine you forgot to type the & character after dolphin. Simply type ctrl+z, which will stop your process and put it in idle. To resume the stopped process, type:
bg
…which will restart the process from the background.
### jobs, ps ###
Now that we have processes running in the background, you can list them either using jobs, or using ps. Try it. Just type jobs, or type ps. Heres what I get:
nenad@linux-zr04:~> ps
PID TTY TIME CMD
8356 pts/1 00:00:00 bash
8401 pts/1 00:00:00 dolphin
8406 pts/1 00:00:00 kbuildsycoca4
8456 pts/1 00:00:00 ps
### Kill a Process ###
How do you get rid of a process if its become unresponsive? By using the kill command. Lets try it out on our previously mentioned dolphin process. First, we have to identify the PID of the process by using ps. In my aforementioned case its 8401 for dolphin. So to kill it, I simply type:
kill 8401
…and it kills off dolphin.
### More About Kill ###
Kill doesnt exist only for terminating processes, but it was originally designed to send signals to processes. And of course, there are a number of kill signals you can use, which can be different in regard to the application you use. See the table below:
![](https://news.opensuse.org/wp-content/uploads/2014/08/snapshot1.png)
Do try them out.
### Conclusion ###
With this lesson, we conclude our CLT series and our tuesday hanging out. I hope that other n00bs like me managed to demistify the console in their minds and learn the basics. Now all thats left is for you to play around (just dont mess around the / directory too much so you dont bork something :D).
Well be seeing a lot more of each other soon, as theres more series of articles from where these came from. Stay tuned, and meanwhile…
### …have a lot of fun! ###
--------------------------------------------------------------------------------
via: https://news.opensuse.org/2014/08/12/command-line-tuesdays-part-eight/
作者:[Nenad Latinović][a]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出
[a]:https://news.opensuse.org/author/holden87/

View File

@ -0,0 +1,67 @@
命令行星期二——第八部分
================================================================================
极客们我们回来了来完成最后一章的CLT。今天我们将讨论一下任务控制。在这个里头我们也将学习怎样来控制运行在我们计算机上的进程
### 一个例子 ###
正如我们所学的我们可以直接在CLI中输入程序名称来运行该程序。例如dolphin。如果我们输入
dolphin
……dolphin这个文件管理器就打开了。如果在进程打开时你查看终端你就不能访问命令提示符了而且你也不能在同一个窗口中写一个新命令进去了。如果你终止dolphin提示符又会出现了而你又能输入一个新命令到shell中去了。那么我们怎么能在CLI运行一个程序时同时又能获得提示符以便进一步发命令。
dolphin &
……现在你让dolphin文件管理器在后台运行了终端就可以空出来输入你需要的另外一个命令了。
现在假设你忘了在dolphin后面输入&字符你只需要输入ctrl+z它会停止你的进程并把它放到空闲列表中去。要继续停止的进程输入
bg
……它会从后台重启进程。
### jobs, ps ###
由于我们在后台运行着进程你可以使用jobs或者使用ps来来列出它们。试试吧只要输入jobs或者输入ps就行了。下面是我得到的结果
nenad@linux-zr04:~> ps
PID TTY TIME CMD
8356 pts/1 00:00:00 bash
8401 pts/1 00:00:00 dolphin
8406 pts/1 00:00:00 kbuildsycoca4
8456 pts/1 00:00:00 ps
### 杀死进程 ###
如果有个进程无响应了怎么来处理掉它呢可以使用kill命令。让我们在先前提到的dolphin进程上试试。首先我们必须使用ps来鉴别该进程的PID。在我上述情况中dolphin的PID是8401。那么让我们来杀死它我只要输入
kill 8401
……那么它就把dolphin给杀死了。
### Kill更多细节 ###
Kill的存在不仅仅是为了终止进程它最初是设计用来发送信号给进程。当然有许多kill信号可以使用根据你使用的应用程序不同而不同。请看下面的表
![](https://news.opensuse.org/wp-content/uploads/2014/08/snapshot1.png)
务必试试这些信号。
### 结尾 ###
我们以本节课来结束我们的CLT系列和周二必达我希望其他像我这样的新手们能设法在他们的思想中摆脱控制台的神秘而学习掌握一些基本技能。现在对你们而言所有剩下来要做的事就是尽情摆弄它吧只是别把/目录搞得太乱七八糟,因而你也不会诋毁什么东西了 :D
Well be seeing a lot more of each other soon, as theres more series of articles from where these came from. Stay tuned, and meanwhile…
我们将在不久的将来看到其它更多的东西,因为有更多的系列文章来自这些文章的出处。别走开,同时……
### ……尽情享受! ###
--------------------------------------------------------------------------------
via: https://news.opensuse.org/2014/08/12/command-line-tuesdays-part-eight/
作者:[Nenad Latinović][a]
译者:[GOLinux](https://github.com/GOLinux)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出
[a]:https://news.opensuse.org/author/holden87/