How Is a Process Different from a Daemon in Linux?

Question
How is a process different from a daemon in Linux?

Answer
A process subsumes a daemon. A daemon is a process that runs for a long period of time (e.g., the duration the server is on). It may require no interaction with a user. A logging process or a web service like Nginx are examples of daemons.

This answer was paraphrased from page 34 of The Linux Programming Interface.

What Is a Decorator in I.T. or DevOps?

Problem scenario
You have read about decorators in object-oriented programming and in Python. Is there a disambiguation of what a decorator is?

Solution
In object-oriented programming, inheritance allows for an object to change from its class at compile time (according to page 201 of Programming Interviews Exposed). In OOP, the decorator pattern is a structural design pattern (according to the inside of the front cover of Design Patterns) and is a way to modify an object in OOP at run-time (according to page 201 of Programming Interviews Exposed).

How Do You Troubleshoot the pipenv error message “tomlkit.exception”?

Problem scenario
You try to run a pipenv command, but you get an error about “tomlkit.exception”.

Solution
Copy the Pipfile to a new name (to back it up). Delete the original Pipfile. Try to run the command again. If it still fails, try removing pipenv by uninstalling it. Then reinstall pipenv. Then reboot the computer.

How Do You Write a Java Program to Accept a Character as Input and Do Something with It?

Problem scenario
You want to accept user input with a Java program. How do you write such a program?

Solution
Here is the program:

import java.util.Scanner;

public class acceptChar {

public static void main(String[] args) {
System.out.println(“Please enter a character, then press enter: “);
Scanner in = new Scanner(System.in);
char letter = in.next().charAt(0);
System.out.println(letter);
}
}

Why Do Processes Get CPU Time on a Linux OS when Their Nice Level is Set for Unfavorable Scheduling?

Problem scenario
Some processes are a low priority for an OS given their nice level. Why do they eventually run when the OS is active and busy handling processes that have higher priorities? Wouldn’t a nice level that indicates a low priority keep the process starved of receiving resources?

Answer
There is a round robin scheduling algorithm for the CPU to allocate time.

A List of Python Books

1593279280Python Crash Course, 2nd Edition: A Hands-On, Project-Based Introduction to Programming by No Starch Press

1593279922Automate the Boring Stuff with Python, 2nd Edition: Practical Programming for Total Beginners by No Starch Press

1449355730Learning Python, 5th Edition by O’Reilly Media

0134692888Learn Python 3 The Hard Way (Zed Shaw’s Hard Way Series) by Addison-Wesley Professional

1491957662Python for Data Analysis: Data Wrangling with Pandas,

How Do You Run a Bolt Command from a Linux Server to a Windows Server?

Problem scenario
You want to run a PowerShell script or run an interactive command on a Windows server. You have Puppet Bolt installed on a Linux server. You do not need to use SSL. What do you do?

Solution
Run a command like this (but substitute x.x.x.x with the IP address of the Windows server, jdoe with the username and coolpassword with jdoe’s password):

bolt command run “Get-Process” –Targets winrm://x.x.x.x –no-ssl –user jdoe –password coolpassword

To run a script called “cool.ps1”,

How Do You Write a Palindrome Tester Function in Python?

Problem scenario
You want to write a palindrome tester function in Python without the :: operator in the code (that reverses the order of the list). What do you do?

Solution

def palindrome_tester(s):
s = s.lower()
x = len(s) // 2
for i in range(x):
if s[i] == s[-(i+1)]:
pass
else:
return False
return True

var_string = “mmnMM”

if (palindrome_tester(var_string)):
print(var_string + ” is a palindrome!”)
else:
print(var_string + ” is NOT a palindrome!”) …

How Do You Escape or Break from a Method in Python?

Problem scenario
You want to quit a function, or return out of it, when a certain condition is met. How do you do this?

Solution
This program illustrates how it is done. You will want to run the program twice, once by leaving the “5” as it is, and a second time by changing the “5” to “6”.

def cool(x):
if x == 5:
return “There was equivalence”
else:
y = x
print(“This statement is printing as an illustration”)
return “The comparison was NOT equivalent”

var1 = cool(5)
print(var1) …