1 00:00:06,660 --> 00:00:09,420 - This lesson is about interactive shell jobs. 2 00:00:09,420 --> 00:00:10,800 When a user runs a command, 3 00:00:10,800 --> 00:00:13,320 this command is started as a foreground job. 4 00:00:13,320 --> 00:00:16,050 That means that you cannot do anything else anymore; 5 00:00:16,050 --> 00:00:17,643 Your console is occupied. 6 00:00:18,900 --> 00:00:20,970 One thing that might be useful is to 7 00:00:20,970 --> 00:00:23,160 move a running process to the background. 8 00:00:23,160 --> 00:00:25,140 You can do that by using Control + Z, 9 00:00:25,140 --> 00:00:27,930 followed by the bg command. 10 00:00:27,930 --> 00:00:29,910 To start a new process in the background 11 00:00:29,910 --> 00:00:32,130 use Command followed by an & 12 00:00:32,130 --> 00:00:33,900 and you'll never see it in the foreground. 13 00:00:33,900 --> 00:00:36,600 It immediately goes to the background. 14 00:00:36,600 --> 00:00:38,250 To get an overview of all the jobs 15 00:00:38,250 --> 00:00:40,230 that are currently running in the background, 16 00:00:40,230 --> 00:00:42,150 you can use the jobs command. 17 00:00:42,150 --> 00:00:44,400 And the fg command is what you can use 18 00:00:44,400 --> 00:00:46,740 to move a current job back- 19 00:00:46,740 --> 00:00:48,960 And the fg command is what you use 20 00:00:48,960 --> 00:00:51,690 to move a current background job back to the foreground. 21 00:00:51,690 --> 00:00:52,533 Let me show you. 22 00:00:55,140 --> 00:00:58,410 So let me start a command that's doing nothing. 23 00:00:58,410 --> 00:01:03,410 dd if=/dev/zero of=/dev/null 24 00:01:04,230 --> 00:01:07,380 It's basically copying nothing to nowhere. 25 00:01:07,380 --> 00:01:10,920 If I press enter, it occupies my console, as you can see. 26 00:01:10,920 --> 00:01:13,380 So there's nothing else that I can do anymore. 27 00:01:13,380 --> 00:01:17,283 So I need Control + Z to temporarily stop it. 28 00:01:18,810 --> 00:01:21,030 If you use the jobs command at this moment, 29 00:01:21,030 --> 00:01:23,250 we can see that the job is temporarily stopped. 30 00:01:23,250 --> 00:01:26,310 And that's because it's waiting for me to type bg 31 00:01:26,310 --> 00:01:29,760 to continue running it in the background. 32 00:01:29,760 --> 00:01:32,610 Now I can immediately run my jobs in the background 33 00:01:32,610 --> 00:01:36,900 by putting an & behind it, as you can see right here. 34 00:01:36,900 --> 00:01:38,460 And let's do that one more time 35 00:01:38,460 --> 00:01:39,930 so that we have a couple of jobs 36 00:01:39,930 --> 00:01:42,150 and here we have the jobs command 37 00:01:42,150 --> 00:01:44,580 and the jobs command is showing all of them. 38 00:01:44,580 --> 00:01:47,670 Now, if I want to move one of these jobs to the foreground, 39 00:01:47,670 --> 00:01:51,570 I can use fg for foreground followed by job number. 40 00:01:51,570 --> 00:01:54,390 And now job number two is running on the foreground. 41 00:01:54,390 --> 00:01:55,800 And if I want to stop it, 42 00:01:55,800 --> 00:01:58,500 then I'm using the generic Linux solution 43 00:01:58,500 --> 00:02:01,613 to stop running things: Control + C 44 00:02:01,613 --> 00:02:04,050 There, you can see that the command outputs 45 00:02:04,050 --> 00:02:07,740 that it has copied 12 gigabyte of nothing to nowhere. 46 00:02:07,740 --> 00:02:08,820 Very interesting. 47 00:02:08,820 --> 00:02:10,380 And the jobs command is showing 48 00:02:10,380 --> 00:02:12,780 the other job's still running. 49 00:02:12,780 --> 00:02:14,190 Now, if you use fg, 50 00:02:14,190 --> 00:02:15,990 then we move it to the foreground 51 00:02:15,990 --> 00:02:19,230 and we can use Control + C to stop it. 52 00:02:19,230 --> 00:02:22,140 And one more time, fg and Control + C. 53 00:02:22,140 --> 00:02:23,580 And now they're all gone, 54 00:02:23,580 --> 00:02:26,610 which can be verified with the jobs command. 55 00:02:26,610 --> 00:02:29,400 Now this job management is convenient for users 56 00:02:29,400 --> 00:02:31,623 because users can manage their own jobs. 57 00:02:32,730 --> 00:02:36,000 Administrators can manage everybody's jobs 58 00:02:36,000 --> 00:02:38,450 and that is what we are going to talk about next.