zoukankan      html  css  js  c++  java
  • Job control

    When you run a program from the shell prompt, stdin is connected to your keyboard, and stdout and stderr are connected to your monitor.when you run a program in the background,the input is disconnected(standard input would be connected to the empty file /dev/null), but the output connections do not change.if a process running in the background tries to read from stdin, there will be nothing there and the process will pause indefinitely,
    waiting for input.

    If it became necessary to terminate the process before it finished on its own, the user could press either ^C to send the intrsignal or ^\ to send the quitsignal .The only difference was that quit would generate a core dump for debugging.

    Within the Bourne Shell family (Bash, Korn Shell), job control is enabled when the monitoroption is set. This is the default for interactive shells, but it can be turned off by unsetting the option.

    kernel uses the process table to keep track of processes, the shell uses a JOB TABLE to keep track of jobs As the job runs, there will be one new entry in the process table and one new entry in the jobs table.And no matter how many processes it might require — is considered to be a single job,with a single job ID.

    who | cut -c 1-8 | sort | uniq -c
    date; who; uptime; cal 12 2008

    While the job is running, there will be four entries in the process table, but only a single entry in the job table.

    If your job consists of a pipeline with more than one program, the process ID you see will be that of the last program in the pipeline.

    who | cut -c 1-8 | sort | uniq -c &

    [2] 4354

    This tells you that you have started job #2 and that the process id of the last program  is 4354.

    the shell sends you a short status message whenever a background job finishes.

    [1] Done ls > temp

    To pause a foreground job, you press ^Z.This sends the susp signal, which causes the process to pause. When you pause a process in this way, we say that you SUSPEND it or STOP it.When you want to resume working with the suspended program, you move it back to the foreground by using the fg command. Using ^Z and fg in this way enables you to suspend a program.

    suspend & suspend -f
    This pauses the current shell — the one in which you are superuser — and returns you to the previous shell in which ypu are previrous working.The only restriction on suspending shells is that, by default, you are not allowed to suspend your login shell.when you start a superuser shell by using su - instead of su, it creates a login shell If you want to suspend the new shell, you must use the -f(force) option.


    jobs [-l]:display a list of all your jobs[with process id]

    fg:This tells the shell to restart the current job, the one that is flagged with a +character.

    %1 or fg %1:Move job number one into the foreground

    bg [%job...]:Move job number n into the background.

    The UNIX options are preceded by a dash in the regular manner, but the BSD options do not have a dash. Remember this when you are reading the man page: if an option has a dash, it is a UNIX option; if not, it is a BSD option.

     

    Every process is identified by a unique number called a process ID. Every file is identified by a unique number called an inumber.

    For example, to display information about files, we use the ls program , which simply looks in the inode table for its data.Internally, Unix keeps track of processes by using a process table, indexed by process ID. Within the process table, each entry contains information about a single process. Similarly, Unix keeps track of files by using an inode table, indexed by inumber.The root of the process tree is process #1 (the init process). The root of the file tree is the root directory

    To display the file tree, we use the tree program .
    To display the process tree, we use the pstree program.

    there is a fundamental difference between processes and files. Processes are dynamic: at every instant, the data that describes them is changing. Files are comparatively static.

    In order to procure the data they need to do their jobs, both ps and top must use a
    type of pseudo file called a proc file . Within the /proc directory, every process is represented by its own proc file. When a program needs information about a process, it reads from that process’ proc file. This, in turn, triggers a request to the kernel to supply the necessary data.

    Here is another common situation. A foreground process becomes so unresponsive, you can’t stop it no matter what you type, including ^C. First, you can try pressing ^Z to suspend the process. If this is successful, you can then use ps or jobs to find the process and terminate it with kill.If you are using a remote Unix host, you can also simply disconnect from the host. On some systems, when your connection drops, the kernel automatically kills all your processes. Of course, this will kill any other programs that may be running.Whenever you kill a process with children, it has the side effect of killing the children.Thus, you can kill an entire group of related processes simply by finding and killing the original parent.

    Notice that each signal is known by a number, as well as a standardized name and abbreviation (both of which should be typed in uppercase letters).In general, the signal numbers for HUP, INT, KILL and TERM are the same on all systems. However, the other signal numbers can vary from one type of Unix to another. For this reason, it is a good habit to use the names or abbreviations — which are always the same — rather than numbers.

    If you would like to see the full list of signals supported by your system, enter the kill command with the -l(list) option:kill -l

    For security reasons, a regular user id can send signals only to its own processes. The superuser, however, is allowed to send signals to any process on the system.One definition of a daemon is any background process without a controlling terminal, whose parent’s process ID is #1.To find the daemons on your system, use ps and look in the output for a ? character in the TTY column. This indicates that the process is not controlled by a terminal.The best command to use is the variation of ps that displays all the processes that are 

    not controlled by a terminal:If this command does not work on your system, try the following:
    ps -t - | less
    ps -e | grep '?' | less

  • 相关阅读:
    C,C++,VC++有什么区别
    RF & Microarray
    偏最小二乘法
    各种机器学习方法的优缺点
    纠错输出编码法ECOC
    遗传算法GA
    支持向量机SVM
    神经网络NN
    机器学习的基本概念
    SPI通信协议(SPI总线)学习
  • 原文地址:https://www.cnblogs.com/hshuzhao/p/2996389.html
Copyright © 2011-2022 走看看