Tag: Linux command line

  • Linux Tutorial Series – 102 – Signals in operating systems – what are they used for?

    Here is the video version, if you prefer it:

    Today we will take a look at signals. They are very important in regard to operating systems and so they are relevant for Linux. Signals are a way for processes to communicate with one another. (“Signal (IPC),” n.d.)⁠

    Processes can’t access each other’s memory locations. So if Process A has memory locations 0 to 99 and Process B has memory locations 100 to 199, then if Process A tries to access memory location 129, operating system will not allow it.

    But, it is useful for processes to be able to communicate with each other. Let’s say Process A wants to somehow say to Process B “Stop! Stop!”. It can use a signal to do so.

    There are a lot of signals you can send to a process and they are listed here: (“POSIX signals,” n.d.)⁠. You don’t need to know their names. Just know what they are used for – communication between processes (also called inter-process communication (IPC)).

    Thank you for reading!

    References

    POSIX signals. (n.d.). Retrieved February 10, 2020, from https://en.wikipedia.org/wiki/Signal_(IPC)#POSIX_signals

    Signal (IPC). (n.d.). Retrieved February 28, 2020, from https://en.wikipedia.org/wiki/Signal_(IPC)

  • Linux Tutorial Series – 101 – The jobs command

    Here is the video version, if you prefer it:

    The jobs command displays status of jobs in your current Terminal session. (Barrett, 2016)⁠ Jobs are programs you are running in your current shell. The difference between jobs and processes is that processes are a operation systems term, while jobs are shell specific term – job is any program you start in the shell (whether in the foreground or in the background). (“What is the difference between a job and a process?,” n.d.)⁠

    I never used this command so far, so just mentioning it here.

    Thank you for reading!

    References

    Barrett, D. J. (2016). Linux pocket guide (3rd ed.). O’Reilly Media. Page 40

    What is the difference between a job and a process? (n.d.). Retrieved February 28, 2020, from https://unix.stackexchange.com/questions/4214/what-is-the-difference-between-a-job-and-a-process

  • Linux Tutorial Series – 100 – The top command

    Here is the video version, if you prefer it:

    To view processes dynamically, use top. (Shotts, 2019) It displays which processes are using up your resources the most – the ones using the most resources is always at the top of the list.

    An example:

    mislav@mislavovo-racunalo:~$ top

    top - 20:34:02 up 96 days, 2:55, 1 user, load average: 1.11, 0.79, 0.62

    Tasks: 237 total, 1 running, 235 sleeping, 0 stopped, 1 zombie

    %Cpu(s): 5.2 us, 0.7 sy, 0.0 ni, 93.3 id, 0.0 wa, 0.0 hi, 0.7 si, 0.0 st

    MiB Mem : 7853.8 total, 985.1 free, 4153.0 used, 2715.7 buff/cache

    MiB Swap: 8066.0 total, 6826.2 free, 1239.8 used. 3013.4 avail Mem

    PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND

    1145 mislav 20 0 874948 216852 29184 S 33.3 2.7 89:30.61 gedit

    6729 mislav 20 0 4991000 460424 110440 S 13.3 5.7 1631:07 gnome-she+

    15544 mislav 20 0 11276 3644 3060 R 6.7 0.0 0:00.01 top

    ...

    ⁠I won’t go into the details of the column names or the meaning of each element of the summary statistics here. I will leave that for review, when we cover all of the relevant concepts. For now, just remember that top is a command that displays the processes with the most resource-intensive processes closer to the top of the process list.

    Hope you learned something useful!

    References

    Shotts, W. (2019). The Linux Command Line, Fifth Internet Edition. Retrieved from http://linuxcommand.org/tlcl.php. Pages 137-139

  • Linux Tutorial Series – 99 – The ps command

    Here is the video version, if you prefer it:

    The ps command is used to display the processes which are currently running. By running ps without any options, you get the processes associated with the current Terminal, as so:

    mislav@mislavovo-racunalo:~/Linux_folder$ ps

    PID TTY TIME CMD

    10653 pts/1 00:00:00 bash

    31210 pts/1 00:00:00 ps

    PID is process ID. TTY is the controlling terminal associated with the process – this field is irrelevant. TIME is processor time the process is taking up – the more processor time a process takes up, the more demanding it is. CMD is the command with which we started the process; it’s the name of the process, with arguments, if arguments exist. (Shotts, 2019)⁠

    ps x gives us all the processes that our current user is running. An example:

    mislav@mislavovo-racunalo:~/Linux_folder$ ps x

    PID TTY STAT TIME COMMAND

    1145 ? Sl 78:18 /usr/bin/gedit --gapplication-service

    3350 ? Ss 0:22 /lib/systemd/systemd --user

    3351 ? S 0:00 (sd-pam)

    3455 ? Ssl 1397:59 /usr/bin/pulseaudio –daemonize=no

    ...

    The new column STAT is short for state. State is the process state – it indicates what the process is doing. The first capital S means that process is sleeping, and that means the process is waiting for input. There are other process states, which you can learn more about by typing man ps and navigating to a section titled PROCESS STATE CODES.

    ps aux gives us the processes of all users. Its sample output is:

    mislav@mislavovo-racunalo:~/Linux_folder$ ps aux

    USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND

    root 1 0.0 0.0 170896 5584 ? Ss 2019 26:40 /sbin/init

    root 2 0.0 0.0 0 0 ? S 2019 0:01 [kthreadd]

    root 3 0.0 0.0 0 0 ? I< 2019 0:00 [rcu_gp]

    root 4 0.0 0.0 0 0 ? I< 2019 0:00 [rcu_par_gp]

    As you can see here, we can see which user started each process (the column USER). We have a couple of additional columns – %CPU signifies how much CPU (in percentages) the process are using, %MEM is the percentage of RAM the process are using, VSZ is the virtual memory size (think of virtual memory as being as large as your hard drive and RAM size combined), RSS (Resident Set Size) is the amount of RAM the process is using in kilobytes, and START is the time when the process had started.

    This is how you can take a look at the processes running in your computer.

    Hope you learned something useful!

    References

    Shotts, W. (2019). The Linux Command Line, Fifth Internet Edition. Retrieved from http://linuxcommand.org/tlcl.php. Pages 135-137

  • Linux Tutorial Series – 98 – Background and foreground processes

    Here is the video version, if you prefer it:

    There exist two kinds of processes. Ones that execute in the background and ones that execute in the foreground. (Ward, 2014)⁠

    Background processes are useful for situations where the program is going to be running for a long time or you want to be able to use your Terminal while the program is running. We have run all of our commands so far in the foreground – meaning we didn’t get back our Terminal until the command stopped executing. All of the commands we have used so far have relatively short running time so there was no need for running them in the background.

    To give you an example of a program I could run in the background, let’s look at Mendeley (a program I use for citations). I am currently running it in the foreground and it looks like this:

    mislav@mislavovo-racunalo:~/Downloads/mendeleydesktop-1.19.4-linux-x86_64/bin$ ./mendeleydesktop

    See how at the end I don’t have another mislav@mislavovo-racunalo prompt? That’s because Mendeley is running in the foreground. If I wanted to run it in the background, I would write an & at the end of the command to start Mendeley and I would get something like this:

    mislav@mislavovo-racunalo:~/Downloads/mendeleydesktop-1.19.4-linux-x86_64/bin$ ./mendeleydesktop &

    [1] 27961

    mislav@mislavovo-racunalo:~/Downloads/mendeleydesktop-1.19.4-linux-x86_64/bin$

    And I have my prompt back. Mendeley is now started in the background. The number 27961 is Mendeley’s process ID which I can use to manipulate it.

    This is for you to know that you can run processes both in the background and in the foreground and to know what & is used for. Also, remember that every process has its process ID (PID), no matter if it is started in the foreground or the background.

    Hope you found this useful!

    References

    Ward, B. (2014). How Linux Works: What Every Superuser Should Know (2nd ed.). No Starch Press. Pages 32-33

  • Linux Tutorial Series – 97 – User identification, authentication and authorization

    Here is the video version, if you prefer it:

    Today we are going to talk about identification, authentication and authorization. We will explain it on an example of me getting into a club.

    Let’s say I want to get into a club. I approach the bouncer, and he asks me who I am. I answer with my full name. That is identification – I provided my identity. Then the bouncer asks me to prove my identity (either via my identity card or whatever else). That is called authentication. Then, if my identity card is valid and the bouncer verifies who I am, then the bouncer checks “the list” and sees if I am on the list – that is authorization. Authorization is checking if a particular user has particular rights – in this case, if I am allowed to enter the club. I enter the club and thus this LinkedIn article is nearing its end.

    These mechanisms exist within the operating system and are important for security. Think of operating system as the club bouncer and of me as someone trying to mangle around with the processes running on my computer. We talked about user IDs associated with the process IDs. So, for example, if I am a user with ID 4 trying to modify a process started by user with ID 5, I would not be authorized to do so and the operating system would not allow me to do so. I don’t think it’s important for you to know the details of how this is done exactly, but just to know that this is done so that there is some measure of security within the system. This may not matter much if you are the only user on your computer, but imagine if there are multiple users – then it starts to matter.

    Hope you learned something useful!

  • Linux Tutorial Series – 96 – Process IDs, owners etc.

    Here is the video version, if you prefer it:

    Let’s introduce some concepts. A process is your operating systems container of a running program. Every application you run has its own process. Every process has its own memory and must not access other processes memory.

    That being said, each process has its own unique process ID (also known as PID). Each process can be uniquely identified via its process ID.

    Each process has an user associated with it – the user which instantiated the process. That user has an ID, and that users ID is remembered. Why is it remembered? So that only the user who initiated the process can affect its execution – start it, stop it etc.

    There are in fact more than one user IDs, but in reality, nothing bad will happen if you simplify it and treat every process as having only one user ID. (Ward, 2014)⁠

    Hope you learned something new!

    References

    Ward, B. (2014). How Linux Works: What Every Superuser Should Know (2nd ed.). No Starch Press. Pages 162-163

  • Linux Tutorial Series – 95 – Checkpoint

    Here is the video version, if you prefer it:

    Moving on, we will learn about processes. We will talk about commands related to process monitoring and management and concepts relevant to truly understand process-related activities.

    This is probably my favorite part, not only because it is fundamental to understanding the Linux operating system and operating systems in general, but because this was challenging to explain – to cull out what isn’t essential, but still give you the bigger picture. I hope that you will find it a joyful read.

  • Linux Tutorial Series – 94 – Review

    Here is the video version, if you prefer it:

    We looked at both Emacs and vi and took a stroll around their basic commands. Here are the most essential of the essential:

    Emacs:

    • C-x 1 (C-x means CTRL + x) for closing all but one window
    • C-x C-s for saving a file
    • C-Space, then C-w for cutting (killing) a piece of text
    • C-y for pasting (yanking) a piece of text

    vi:

    • There are two modes – insert and command
    • To enter insert mode, press i, or to append to the end of the line the cursor is on, press A
    • Escape insert mode with Esc
    • Delete characters (while in command mode) with x
    • Save and quit by writing :wq and pressing Enter

    Talk soon!

  • Linux Tutorial Series – 93 – Customizing the prompt

    Here is the video version, if you prefer it:

    You can customize the prompt in your command line. The prompt is the thing that is displayed left of your cursor when you first start a Terminal. My prompt is mislav@mislavovo-racunalo:workingDirectory, but it could be something else.

    I won’t go into details here, because I don’t care about fancy – I care about day-to-day Linux usage, and customizing the prompt doesn’t fit that topic. You can find more about it here: (“How To Customize Bash Prompt In Linux,” n.d.) and (Shotts, 2019)⁠.⁠

    Thank you for reading!

    References

    How To Customize Bash Prompt In Linux. (n.d.). Retrieved February 9, 2020, from https://www.ostechnix.com/hide-modify-usernamelocalhost-part-terminal/

    Shotts, W. (2019). The Linux Command Line, Fifth Internet Edition. Retrieved from http://linuxcommand.org/tlcl.php. Pages 186-194