Skip to content

Simple C and C++ programs that are useful to systems and embedded programmers.

License

Notifications You must be signed in to change notification settings

chaiken/util-scripts

Folders and files

NameName
Last commit message
Last commit date

Latest commit

262d33f · Jul 29, 2024

History

77 Commits
Feb 25, 2023
Jul 27, 2024
Dec 26, 2022
Mar 12, 2015
Jul 29, 2024
Feb 20, 2023
Jul 27, 2024
Jul 27, 2024
Jul 27, 2024
Jul 27, 2024
Jul 27, 2024
Jan 16, 2023
Jan 1, 2023
Jan 16, 2023
Jul 27, 2024
May 4, 2014
Jul 27, 2024
Apr 2, 2023
Jul 27, 2024
Jul 27, 2024
Jul 27, 2024
Jul 27, 2024
May 4, 2014
Jul 27, 2024
Jun 23, 2015
Jul 27, 2024
Jul 4, 2024
Jul 27, 2024
Jul 27, 2024
Jul 27, 2024
Jul 27, 2024
Jul 29, 2024
Jul 28, 2024
Jul 29, 2024
Jul 20, 2015
Jul 20, 2015

Repository files navigation

Here are some simple C and C++ programs that are useful to systems programmers.

  1. classify_process_affinity_lib provides C++ functions that determine whether "man 1 tasket," or, equivalently, "man 2 sched_setaffinity" is able to modify the CPU affinity of a given Linux thread. Examples of threads that are not pinnable are per-CPU threads like ksoftirqd/* and kworkers.

  2. cpumask calculates hexadecimal cpumasks that are useful with, for example, /usr/bin/taskset from util-linux.

  3. hex2dec and dec2hex perform the format conversions that should be obvious from their names. They will read either from stdin or from the command-line, making the following the obvious test:

      $ hex2dec 0xFFF | dec2hex<br/>
      0xFFF
    
  4. hexsum is a bash script that performs addition or substraction on a pair of hex numbers by invoking hex2dec.

  5. watch_file and watch_one_file provide a simple method for the user to spy on which files another program is accessing without generating the giant spew of strace.

  6. cdecl is a program originally suggested by Kernighan and Ritchie on p. 100 of the Second "ANSI C" Edition of The C Programming Language in the section "Complicated Declarations." They say "we will present a pair of programs that convert from valid C to a word description and back again. The word description reads left to right." I only wrote the program that converts C into English. K&R present a simpler version of cdecl as an example, while more featureful versions like that presented here are outlined in Exercises 5-18 and 5-20.

    The problem is also discussed by Peter van der Linden in the Programming Challenge of Chapter 3, p. 85 of Expert C Programming: Deep C Secrets, p. 85 of Chapter 3. The challenge is "Write a program to translate C declarations into English". I wrote this version without first consulting either of van der Linden's or K&R's versions. Theirs are more elegant, but I have confirmed that mine reproduces their answers. Caveat emptor!

    cdecl also works either with command-line or stdin input. In the latter case, use '-' as an argument after the "cdecl" command:

      $ echo "char *foo;" | cdecl -<br/>
      foo is a(n) pointer(s) to char
    

    Processing command line input adds considerable complexity to the program, as does the limited error checking. I've attempted to support all the features of C declarations described in ANSI C with the exception of those noted in the usage() output.

Alison Chaiken
alison@she-devel.com

About

Simple C and C++ programs that are useful to systems and embedded programmers.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published