• Linux
  • August 2018
    M T W T F S S
    « Jul    
  • Meta

  • Follow me on Twitter

  • Advertisements

Linux is user friendly



Revisiting Old Code

I recently found some of my C programming books, reviving my interest. It’s been nearly 20 years since I’ve written any source code and I’m quite rusty. A couple of my books and the copy of The C Programming, Second Edition by Kernighan & Ritchie were written in the late 1980s and early 1990s and many of the example program listings don’t conform to modern C standards which makes relearning C a bit more challenging. It also doesn’t help that I don’t remember much from my programming classes and such.

I happened to find a notebook contain some of the source code I wrote as a student. Much of that code no longer makes much sense to me, largely because I’m no longer familiar with the mathematical problems they were meant to solve and I don’t remember much about C data structures either.

I did find my source code for a program I wrote that reads a text file of C or C++ source code and counts how many lines of code it contains disregarding comments and blank lines, and displays the result.

I later modified the program to identify functions and count their lines of code. This program listed all of the functions and their respective counts, then displayed a summary of the total number of functions, total lines of code contained in functions, and total lines of code for the program.

I haven’t been able to locate the original source files so I’ve been typing them into an editor from my printed source code. I’m very prone to making typographical errors so proofreading and fixing the code can get tedious. It’s fortunate that I had the foresight to thoroughly document the original code to include function descriptions, parameters, outputs, possible side effects and limitation. I think I made three versions of the second program but I can only find the source for the first two versions.

I got the program that simply counts the lines of code (loc.c) compiles and it works. I even made a couple modifications to the displayed output. I entered the code for the second version of the function counting program (fn_loc.c) and got it to compile. However, I immediately get a segmentation fault when I try to run it. I know that it worked when I wrote it 20 years ago. I used it to print out summaries of the programs in my notebook.

The fn_loc.c program uses a stack to store a simple data structure containing the name of each function and its lines of code count and that’s where I suspect the problem lies. It’s probably a misplaced pointer.

I did a little research on debugging and recompiled the code with the debugging information included:

$ gcc -ggdb -Wall -o fn_loc fn_loc.c

Without even running the gdb debugger, the compiler’s output pointed me to the line containing my error in the function that created the stack:

s – (STACK)malloc(sizeof (struct node));

The error was obvious. The ‘-‘ should have been ‘=’. The stack was never created and the variable ‘s’ was never initialized. I corrected the error, recompiled it, and the program ran perfectly.

The compiler showed another error that I don’t quite understand:

fn_loc.c: In function ‘main’:
fn_loc.c:103:5: warning: enumeration value ‘NewLineNC’ not handled in switch [-Wswitch]

NewLineNC is one of the enumerated type values I created to track the state of the line being examined. It’s used as a transitory state in several of the functions that determine the new state after a character has been examined. I don’t seem to have an need for in in main().

That program was one of the more useful programs I wrote in school and I enjoyed writing it.

My renewed interest in programming is mostly for my own enjoyment, something to challenge my mind and keep it active. Of all the languages I used in school, C was my favorite and my go to language if I had a choice. I dabbled in Ada, C++, Java, Lisp, Pascal, and Visual Basic but only learned enough to complete assignments. Even C was self-taught. I spent a lot of time looking up functions in my Borland compiler manual or other reference books.

How has Linux changed my life?

Tux_MonoI recently saw a YouTube live stream video with the theme of “How has Linux changed my life?” and it got me thinking about it. However, before I get into how Linux changed my life, I want to briefly go over my history with Linux.

My relationship with Linux started in the early nineties using Unix and VAX systems for my Computer Science coursework in college. Some time in the late nineties I downloaded Slackware Linux and put it on a bunch of floppy disks.. I installed it on a computer to see what it was like but didn’t really use it. At some point I found a DOS program that sort of emulated the Linux command line by substituting Linux equivalents for DOS commands.

In early 2006, I built myself a Web server out of spare parts which I appropriately named FrankenWeb. I installed Debian 3.1 rt on that and with the help of my son, got it up and running. About a year and a half later, the hardware started getting flaky so I built another server, FrankenWeb Jr., and loaded it with Ubuntu 7.10 Server. That served me well until mid-2010 at which time I moved all of my web content to hosted server. Around that time I was messing around with setting up Linux DNS and NTP servers on my home network.

In the later part of 2009, I bought a refurbished Gateway laptop which I dual booted with Windows XP and Ubuntu 10.04 LTS. In 2014 I wiped the drive and installed Linux Mint 15 Cinnamon on it. Just this year, I pulled it out of mothballs and installed MX Linux 17 on it.

At some point in 2010, I put Ubuntu 10.04 LTS on a desktop machine and have been using Linux on the desktop ever since. In November 2011 I installed 11.04 but didn’t like it so I went back to 10.04. That was probably when they introduced the Unity desktop. About a year later I upgraded to 12.04 and changed from the Unity desktop to Gnome. I’m not sure exactly when I changed over Linux Mint, probably around 2014 and it’s been my go-to distribution ever since. I’ve looked at others but I keep going back to Mint.

How has Linux changed my life? It’s tempting to answer that with a multitude of reasons why I use Linux but that doesn’t answer the question. It has definitely reduced my dependence on Windows and Microsoft software, especially since I haven’t like the direction Microsoft has been taking with Windows 8, 8.1 and 10. I have to deal with Windows 10 in my part-time job and I find myself growing increasingly intolerant of its peculiarities and annoyances.

The further I move away from Windows, I find I’m less stressed out by technology. As Douglas Adams once said, “We are stuck with technology when what we really want is just stuff that works.” Linux works. It does what I tell it to do, not what it thinks I want it to do or what it wants me to do.

Linux and open source fit well in to my life philosophy. I value cooperation, collaboration and adaptability over competitiveness, rigidness, and unquestioning conformity. Well, that’s a reason for using Linux, not how it’s changed my life. But it’s made me a happier computer user.

Using Linux has made me a more discriminating and conscientious computer user. It has reinforced my natural tendency to not follow the crowd and accept whatever is handed to me. It has made me more independent and given me more freedom and greater choices, at least within the technological realm.

As a Linux user, I’ve become a more knowledgeable computer user and I have a greater understanding of what’s going on under the hood. I’m less frustrated by the technology I use when I have greater degree of control over it.

Rsync on Windows

tux-rsync-winFor the last couple of days I’ve been messing with Cygwin and rsync to provide me with a means of creating backups of the data on my Windows systems. I seem to have it working now on my Windows 7 PC so I’m getting ready to set it up on my wife’s computer. The plan is to create periodic backups on USB hard drives then keep one back up of each off site.

Once I got the basic syntax worked out my first backup seemed to be successful but when I tried to access folders and files on the backup, I was met with messages saying that I did not have permission. After some searching through forums I found a work around to do a chmod on the backed up files giving me the proper permissions. I reformatted the backup drive and tried again, with success. I had a little over 120GB of data to be backed up so it took a while.

After successfully testing to be sure I could access the data, I did some file clean up of my hard drive – moving files and folders around and deleted some unneeded stuff – then ran it again. This time it was much quicker because it only need to back up what had changed.

I like the idea of using rsync to do backups but the Cgywin implementation of Linux in Windows takes little getting used to and has an added level of complexity in bridging between Windows and Linux. I’m only using rsync to back up to an external drive rather than over a network. I may take a look at doing it over SSH in the future but, for now, this solves the immediate problem.

C:\cygwin64\bin\rsync -avhP –no-p –chmod=ugo=rwX –delete “/cygdrive/C/Users/Rick/” “/cygdrive/E/Backup/”

Old Diskettes

For some reason I found myself thinking about the code I wrote many years ago both in my Computer Science studies and for my own edification. I found a notebook containing some C and C++ code but I’m sure I kept a hard copy of every program I wrote in school but I haven’t found it yet. I’m also sure I have it on floppy disks. (Yeah, it was that long ago.)

I started searching through various boxes of diskettes and, for some reason, I still have a lot of diskettes. I’ve got utility and boot disks from 20-plus years ago when I worked for URC. Among this diskettes I found were Windows NT 4.0 and Windows for Workgroups 3.11, still in the original, unopened plastic wrapper.


I know I have another set of WFWG 3.11 diskettes and CDs for NT 4.0 and Windows 2000 Professional and Advanced Server somewhere. It’s been a very long time since I’ve used any of these operating systems. I might have CDs for SCOUnix from when SCO was giving them away. The oldest Linux distribution I have stashed away is Ubuntu 8.04 LTS.


Windows 7 install

Probook6570bFor a little change of pace, I installed Windows 7 on a HP ProBook 6570b. I did this for someone else and after installing Linux for so long, it was a bit of an adventure that made me appreciate Linux even more. (Installing Windows 10 at work really makes me appreciate Linux!)

The base installation of Windows 7 went fairly quickly and then the fun began with installing Service Pack 1, all the device drivers, countless updates, and the software. Being Windows, there were numerous reboots and the whole process took two or three hours. Overall, as Windows 7 installations go, it went very well.

Later on I decided to install web cam software on my laptops and discovered that two of them had a built-in camera. That got me to thinking, in Linux everything is a file so I should be able to use the command line or a script to check if the device existed. I came up with two ways to check it in a script and they both worked. I took the simpler test and added it to my installation script to install guvcview if /dev/video0 or /dev/video1 existed. Out of curiosity, I plugged my Logitech web cam into my desktop PC, checked its existence and installed the software.

Trying MATE

This morning, I updated the kernel on my Dell Latitude E6500 and when I tried to reboot I got the following error:


I did a search on it and found lots of suggestions, like removing old kernels, turning off autologon (which I don’t use), and removing the gnome-keyring-daemon. There only only a few old kernels on the system since I reloaded it just a few months ago but removing them didn’t help. I ran Timeshift and reverted back to yesterday’s snapshot when the system was working correctly but to no avail. I recall that I had some issues with that (or something similar a couple of years ago when I had Mint 17.3 on it and I was using autologon. At that time I turned autologon off and the problem went away.

Well, I’d been thinking about reloading it and changing the partition scheme anyway so I decided I’d install Mint 18.3 MATE on it. The installation went well and I restored my home directory. We all should know that there is no such thing as a simple upgrade and this was no exception although the problems were relatively minor.

After the install, I connected it to an external monitor and the display settings wouldn’t see it and it didn’t properly recognize the laptop display either. The fix was to install the open source driver for the NVIDIA graphics adapter which the install had selected by default anyway. I had changed it to the “recommended” proprietary driver. Once I had the right driver, everything was right with the display.

The other problem was that my Conky script would disappear from the desktop whenever I opened something or clicked on the desktop. I fixed that by editing the script and changing the “own_window_type” from desktop to dock.

Now, everything seems to be working okay and I just need to mess around with the MATE environment and get used to it. I’ve been using Cinnamon for long time but,I’ll adjust. MATE is based on GNOME2 and I used GNOME on Ubuntu until they went to Unity as their desktop. Then I switched to Mint and Cinnamon. It’s good to try something new.

My Mint-installs script worked pretty well and installed all my software.


%d bloggers like this: