First page Back Continue Last page Overview Image
Jobs & job control
- The OS distributes resources to active programs.
- OS processes services and controllers (called daemons) run silently in the background. All have a Program Information File number (PIF).
- To interact with a background process yo issue a signal trough its PIF, using the kill command.
- kill -s SIGTERM # signal 15, asks the program to stop.
- kill -s SIGKILL #9 signal 9, ask the OS to terminate the application.
- To launch my program I ask the SHELL. the SHELL is the parent and my program is a child job. I can communicate with this process through the active SHELL. But I can execute my program in a detached SHELL using the & symbol at the end of the line.
- When done, the child returns control to the parent, but if a parent stops it stops all its sibling jobs (called %1 to %n).
- A child job running in the foreground (fg) makes the SHELL wait for it to finish. But the background (bg), the SHELL can take more commands.
- The output of a child job appears in the same SHELL terminal. But the children output can be redirected, to keep the terminal neat and store the results.
Notes:
El OS da recursos a todos los programas, incluyendo los servicios y los demonios que manejan el hardware y señales de software, los cuales corren silenciosos en el fondo.
Para lanzar mi programa se lo paso al Shell que lo pasa al OS. El Shell es ahora el padre y el programa su hijo.
Cuando finaliza, el trabajo hijo devuelve el control al padre.
Pero si el padre muere anticipadamente, el hijo queda difunto, a menos que corra despegado del padre (indicado con & al final de la línea).
Para interactuar con un programa del fondo, necesito enviarle una señal, por ejemplo, SIGTERM (15), que pide terminación anticipada, o SIGKILL (9) que lo vuelve difunto.
En la terminal, los trabajos hijos se llaman %1, %2, etc. Si se ejecutan al frente, la terminal queda detenida hasta que el trabajo termine, pero si se corren en el fondo, sigue activa, aunque el trabajo esté corriendo.
Para que la salida de los procesos corriendo en el fondo no se mezcle en la terminal, la salida de cada proceso se puede redirigir.