Programming

  • Process synchronization

    1.0 Problem

    Suppose there are n concurrent peer processes, where n > 1. All these processes have a checkpoint, which is an important point in the execution trace of the process. These processes need to be synchronized such that no process crosses its checkpoint before the others have reached their individual checkpoints. For example, a software ...

  • Regular Expressions in C

    1.0 Introduction

    Regular expressions are used for searching strings in text files. A regular expression is a string of characters and may contain certain metacharacters. A metacharacter has a special meaning. A regular expression denotes a set of strings. Or, in other words, there is a set of strings that are matched by it.

  • Dining philosophers problem

    The dining philosophers problem is about deadlock in concurrent systems. The dining philosophers problem is explained with example programs.

  • Program to generate a random password in C

    1.0 Introduction

    Passwords provide a level of security for digital assets. To be effective, passwords need to sufficiently long. random and chosen from a big underlying domain.In this post, we have a C-language program, that takes in number of characters in the password as input, and chooses a random password from printable ASCII characters. The program ...

  • C Programming Tutorial 5: Structures and Unions

    1.0 Structures

    A structure, in the C programming language, is a collection of variables for an entity. The variables are known as members of the structure and are located at consecutive memory locations. The size of the structure is the sum of sizes of the members plus any padding that might be placed ...

  • C Programming Tutorial 4: Pointers and Arrays

    1.0 Introduction

    A pointer variable holds the address of another variable. It is said to be “pointing” to that variable. For example,

    int *ip;
    

    defines a variable ip of type integer pointer. ip points to a variable of type integer. At the implementation level, it holds the address of a variable to type ...

  • C Programming Tutorial 3: Control Flow and Functions

    1.0 Introduction

    A C program comprises of global data and functions. A program must have a main function and the execution starts at the first statement in the main function. A function has local data and statements. The control flow deals with the order in which statements are executed by a program. In this post, we ...

  • C Programming Tutorial 2: Data Types and Expressions

    1.0 Introduction

    Data is an important part of a program. In fact, programs are written so that data can be captured, processed, stored and presented to the user. The success of a program depends on how well data has been organized and used. In this post, we will be looking at data types and expressions in ...

  • C Programming Tutorial 1 – Getting Started

    1.0 Introduction

    C is a procedural programming language invented by Dennis Ritchie in 1972. C is, possibly, the most widely used programming language in the last fifty years. There are some unique features of C. It is a small language; so it can be ...

  • I/O multiplexing: select, poll and epoll in Linux

    1.0 I/O multiplexing

    I/O multiplexing is the the ability to perform I/O operations on multiple file descriptors. Input operations like read, accept and calls for receiving messages block when there is no incoming data. So, if an input call is made and it blocks, we may miss data from other file descriptors. To circumvent this, I/O ...

  • POSIX real-time signals in Linux

    1.0 Signals

    Signals are notifications delivered asynchronously to a process by the kernel. Signals are grouped in two categories. First, there are standard signals, which have been there since the early days of Unix. Second, there are POSIX real-time signals which are specified in POSIX.1b, or, IEEE Std 1003.1b-1993, for Real-time Extensions for ...

  • How to create a temporary file in Linux

    1.0 Temporary Files

    Quite often, we need temporary files in our programs. Some intermediate data needs to be stored and the file can be discarded when the process terminates. There are multiple ways of creating temporary files in Linux. The best way to create a temporary file in Linux is to use the

  • Interprocess Communication using Unix Domain Sockets

    1.0 Unix Domain Sockets

    A socket is a communication endpoint at a host computer. The socket API provides calls for communication between processes. The socket system call is,

    int socket (int domain, int type, int protocol);
    

    The first parameter to the socket system call is the domain. The domain is actually the communication domain and it selects ...

  • File I/O in Linux

    1.0 Input and Output (I/O)

    All programs need to interact with the external world which makes I/O important. Programs store data in files which provide large persistent storage. In this post we will look at the system calls and functions for file I/O and the issues that govern the program and I/O device interaction.

    2.0 Buffered I/O

    Reading ...

  • How to trim a string in C

    Trim a string

    The problem of removing leading and trailing whitespace characters in strings occurs in programming quite often. Here is a solution.

    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <ctype.h>
    
    void trim (char *dest, char *src); 
    
    int main (int argc, char ...
Tags: