1
00:00:00,004 --> 00:00:01,009
- [Presenter] There is a lot of information

2
00:00:01,009 --> 00:00:03,003
available from the Kernel.

3
00:00:03,003 --> 00:00:07,002
Some of it is messages the Kernel prints,

4
00:00:07,002 --> 00:00:10,007
some of it is information you ask for

5
00:00:10,007 --> 00:00:12,004
by looking at proc files,

6
00:00:12,004 --> 00:00:16,002
or other files and virtual file systems.

7
00:00:16,002 --> 00:00:17,001
So in this chapter,

8
00:00:17,001 --> 00:00:21,005
we're going to talk about messages and proc.

9
00:00:21,005 --> 00:00:23,009
Inside the kernel source code,

10
00:00:23,009 --> 00:00:28,001
are lots and lots of calls to a function called printk.

11
00:00:28,001 --> 00:00:30,002
It's a lot like C's printf,

12
00:00:30,002 --> 00:00:31,007
in case you've seen that.

13
00:00:31,007 --> 00:00:35,001
And it's a way to print text messages.

14
00:00:35,001 --> 00:00:38,009
Those messages go into a RAM buffer,

15
00:00:38,009 --> 00:00:40,007
and you can look at the contents

16
00:00:40,007 --> 00:00:43,000
of that RAM buffer with a command,

17
00:00:43,000 --> 00:00:44,009
command called D message.

18
00:00:44,009 --> 00:00:49,001
Sometimes those messages show up on the system console

19
00:00:49,001 --> 00:00:50,002
if they're important enough,

20
00:00:50,002 --> 00:00:52,002
and that's configurable.

21
00:00:52,002 --> 00:00:56,006
And they're also usually logged for a logging daemon.

22
00:00:56,006 --> 00:01:01,001
And so you can look at the log file for those messages.

23
00:01:01,001 --> 00:01:04,006
So D message is the command to show

24
00:01:04,006 --> 00:01:07,004
the contents of that RAM buffer right now.

25
00:01:07,004 --> 00:01:09,008
And, if you want to look at the log file,

26
00:01:09,008 --> 00:01:12,000
these days, it's typically,

27
00:01:12,000 --> 00:01:16,002
you use the journalctl command, -K,

28
00:01:16,002 --> 00:01:19,006
and that'll show you kernel logged files.

29
00:01:19,006 --> 00:01:24,006
If you do journalctl -k, -f, and let it run,

30
00:01:24,006 --> 00:01:28,002
as the kernel adds more messages, you'll see those.

31
00:01:28,002 --> 00:01:31,001
Sometimes when you're trying to debug something,

32
00:01:31,001 --> 00:01:32,003
it's kind of handy to see

33
00:01:32,003 --> 00:01:35,008
what messages are getting printed.

34
00:01:35,008 --> 00:01:40,000
Linux has a number of virtual file systems,

35
00:01:40,000 --> 00:01:41,006
or pseudo file systems.

36
00:01:41,006 --> 00:01:45,002
They look like file systems with directories and files,

37
00:01:45,002 --> 00:01:48,007
but they're not stored on disc anywhere.

38
00:01:48,007 --> 00:01:52,006
They're totally made up when you ask for 'em.

39
00:01:52,006 --> 00:01:57,000
So you look at a file, underneath proc,

40
00:01:57,000 --> 00:02:00,009
the kernel right then generates its contents.

41
00:02:00,009 --> 00:02:04,004
So by definition, it's always up-to-date information.

42
00:02:04,004 --> 00:02:06,006
Some of these files are writeable.

43
00:02:06,006 --> 00:02:09,006
So you can tell the kernel something like,

44
00:02:09,006 --> 00:02:13,005
"Change this variable to this new value."

45
00:02:13,005 --> 00:02:14,009
And that's often for some sort

46
00:02:14,009 --> 00:02:18,001
of things we'll call tunables.

47
00:02:18,001 --> 00:02:19,009
So all the files have some function

48
00:02:19,009 --> 00:02:21,002
the kernel associated with them

49
00:02:21,002 --> 00:02:26,003
that gets called when you use that file.

50
00:02:26,003 --> 00:02:29,005
Proc is the first, and kind of classic

51
00:02:29,005 --> 00:02:32,004
pseudo file system for Linux.

52
00:02:32,004 --> 00:02:37,004
The proc file system is normally mounted on/proc,

53
00:02:37,004 --> 00:02:39,003
and that should happen at boot time,

54
00:02:39,003 --> 00:02:41,002
so it should be there.

55
00:02:41,002 --> 00:02:44,006
Proc gets its name from process,

56
00:02:44,006 --> 00:02:47,002
and the proc file system has lots

57
00:02:47,002 --> 00:02:51,007
of information about processes and more.

58
00:02:51,007 --> 00:02:55,005
Every process has a subdirectory underneath proc,

59
00:02:55,005 --> 00:02:58,005
and the name of the subdirectory is the process ID.

60
00:02:58,005 --> 00:03:01,005
So if you change directory to /proc,

61
00:03:01,005 --> 00:03:05,004
you'll see lots of process ID numbers.

62
00:03:05,004 --> 00:03:08,007
So the information you could see in proc,

63
00:03:08,007 --> 00:03:11,007
will be information about memory usage of the process,

64
00:03:11,007 --> 00:03:13,001
what program it's running,

65
00:03:13,001 --> 00:03:16,008
what files it has, open watch more, lots more.

66
00:03:16,008 --> 00:03:18,003
There could be hundreds of files

67
00:03:18,003 --> 00:03:20,008
and directories per process.

68
00:03:20,008 --> 00:03:23,005
If a process has multiple threads,

69
00:03:23,005 --> 00:03:26,003
then there's also information about all the threads.

70
00:03:26,003 --> 00:03:29,007
That's underneath a directory called Task.

71
00:03:29,007 --> 00:03:31,002
Have a look at proc.

72
00:03:31,002 --> 00:03:32,004
And then the challenges,

73
00:03:32,004 --> 00:03:34,000
we will look at it a bit too.

