如何在shell脚本中创建作业?

时间:2016-10-17 05:57:36

标签: bash shell

我知道执行命令并在末尾添加&会创建一个作业并使命令在后台执行。

现在我想在bash shell中创建一个作业。我试过了

#!/bin/bash

my-job &
# some other tasks

然后我执行了jobs,但我没有输出。但是,ps aux确实显示my-job正在后台运行。

我想在脚本中创建一个作业,因为在某些情况下我想把这个作业带到前台。

1 个答案:

答案 0 :(得分:1)

var myImage = document.getElementById("photo"); var imageArray=["pictures/1.JPG", "pictures/2.JPG", "pictures/3.JPG", "pictures/4.JPG", "pictures/5.JPG", "pictures/6.JPG", "pictures/7.JPG", "pictures/8.JPG", "pictures/9.JPG", "pictures/10.JPG"]; var imgIndex = getRandomInt(0, imageArray.length); var isIntervalRunning; function changeImage(){ myImage.setAttribute("src", imageArray[imgIndex]); imgIndex++; if (imgIndex >= imageArray.length) { imgIndex = 0; } } function getRandomInt(min, max) { return Math.floor(Math.random() * (max - min + 1)) + min; } var intervalHandle = setInterval(changeImage, 6000); document.getElementById("title").onclick = function () { location.href = "index.html";} document.getElementById("aboutbutton").onclick = function () { location.href = "about.html";} document.getElementById("contactbutton").onclick = function () { location.href = "contact.html";} document.getElementById("picturesbutton").onclick = function () { location.href = "pictures.html";} 通常是一个交互式shell概念,因为通常涉及一个控制终端。

shell脚本在shell的非交互式非登录会话中执行,因此默认情况下不进行作业控制。

您可以通过设置:

强制脚本中的作业控制
jobs

在剧本中。

来自set -m

help set