Shell Scripting - JOB SPEC & Command Last Updated : 07 Nov, 2022 Comments Improve Suggest changes Like Article Like Report Prerequisites: Bash Scripting, Shell Function Library Processes started from the terminal (and still not terminated) get a unique serial number or ID that is known as job spec or job ID. With the help of the job spec of a particular process, we can send signals to it or make that particular process run in the foreground or background. We can also list all the processes started from terminal and their current status from the jobs utility. The & symbol is used to run processes in the background. As foreground processes don't allow the shell prompt in the terminal to return, there is a constant need for the & symbol to run processes in the background. Syntax of '&' symbol and its working The & symbol is appended at the end to run processes in the background. $ process_name & $ /path/to/process_name & $ process_name <args> & For example, let us start some programs(processes) in the background using the & symbol : Syntax and working of the Job specEvery process gets a unique job spec which is shown enclosed in square brackets [ ]A % symbol is prepended to the job spec when used in a command. With the help of job spec, one can send a signal to that particular process having that job spec or make it a foreground/background process.A job may also be referred to by % followed by the process name.The current job is referenced using %+ or %% while the previous job is by %- Jobs and their respective job specs can be viewed from the command jobs. $ jobs $ jobs %jobSpec $ jobs %processName $ jobs %+ (or %%) $ jobs %- $ fg %jobSpec $ bg %jobSpec $ kill %jobSpec Creating Shell Script We will create a shell script that will launch the processes in the background with the help of & a symbol and then view its job spec. The name of the script will be launch.sh $ touch launch.sh Make it an executable file. $ chmod +x launch.sh Open the file and add the following Script. #!/bin/bash # enabling job control in the script set -m # iterating the list of args which has process names # and launching them in background for process in $@ ; do $process & done sleep 1; # viewing the list of jobs and their job specs echo "Jobs and their jobspecs are :" jobs; sleep 1; echo # killing the processes before the script ends jobspec=1 while (( jobspec <= $# )) ; do kill -SIGINT "%$jobspec" echo "Job having jobspec $jobspec is terminated." (( jobspec++ )) done exit 0Run the Script $ ./launch.sh <args> #args should be program(process) names Comment More infoAdvertise with us Next Article Shell Scripting - JOB SPEC & Command S sushruta19 Follow Improve Article Tags : Linux-Unix Shell Script Similar Reads Shell Scripting - True Command A shell provides an interface with the help of which users can interact with the system easily. To directly interact with a shell, we use an operating system. On a Unix-based operating system, every time we write a command using a terminal, we interact with the system. To interpret or analyze Unix c 3 min read Shell Scripting - Disown Command Shell is a command language interpreter. It is used in most of the UNIX/LINUX-based distros. Shell support scripting means we can automate the Shell commands by writing some scripts with different logic, looping, and decision making. This benefits us to automate some time-consuming and tedious jobs. 5 min read Shell Scripting - Talk Command The use of Shell scripting can simplify repetitive tasks and enable more complex operations with minimal code. Shell commands vary in syntax, with "talk" being a command to facilitate communication among users within the same network. Proper knowledge of the shell, OS, and available commands is nece 6 min read Shell Scripting - Set Command The `set` command in shell scripting is a powerful tool that used for controlling the behavior of the shell and the environment in which scripts run. It allows the users to modify the shell options and positional parameters which facilitates providing greater control over script execution and debugg 6 min read Shell Scripting - Scheduling Commands We need to run the scripts frequently in order to maintain the system infrastructure's cleanliness and security when using a UNIX-based system. These repetitious chores involve system backups, health monitoring, as well as other upkeep duties. Automation is the finest and quickest technique to accom 3 min read Introduction to Linux Shell and Shell Scripting If we are using any major operating system, we are indirectly interacting with the shell. While running Ubuntu, Linux Mint, or any other Linux distribution, we are interacting with the shell by using the terminal. In this article we will discuss Linux shells and shell scripting so before understandi 8 min read Shell Scripting - Define #!/bin/bash A shell provides an interface to connect with the system. When we use an operating system, we indirectly interact with the shell. While using a terminal every time on any Linux distribution system, we interact with the shell. The main function of the shell is to interpret or analyze Unix commands. A 3 min read Shell Scripting - Standard Input, Output and Error Working on Linux applications we have several ways to get information from outside and to put it inside: command line args, environment variables, files. All of these sources are legal and good. But it has a finite size. Another way to establish communication is standard streams: input stream (stdin 7 min read Shell Script to Demonstrate Wait Command in Linux Wait command is one of the process management commands. There are different process commands in Linux mainly 5 commands are widely used which are ps, wait, sleep, kill, exit. ps is an acronym for process status. It displays information about the active processes. wait command will suspend execution 4 min read Shell Scripting - Interactive and Non-Interactive Shell A shell gives us an interface to the Unix system. While using an operating system, we indirectly interact with the shell. On Linux distribution systems, each time we use a terminal, we interact with the shell. The job of the shell is to interpret or analyze the Unix commands given by users. A shell 3 min read Like