SShortSingh.
Back to feed

Declaring, Filling and Reading a C Struct, with a Linux Kernel Example

0
·3 views

The article explains how to use a C struct by first declaring it with the struct keyword, a tag, and a list of fields inside braces. It shows two ways to create a variable of that type: supplying all values at creation inside braces, or initializing to zero and assigning each field separately, with strcpy used for the array-based name field. Field values are read back using the dot operator, such as s1.marks. The author notes common pitfalls, including forgetting the semicolon after the declaration and the need to use strcpy for character arrays. The piece closes with a full example program and a brief look at a small time-tracking struct used in the Linux kernel.

Read the full story at DEV Community

This is an AI-generated summary. ShortSingh links to the original source for the complete article.

Discussion (0)

Log in to join the discussion and vote.

Log in

Related stories

0
ProgrammingDEV Community ·

DEV Community Tutorial Explains JavaScript Callbacks, Promises, Async/Await, and Hoisting

A DEV Community article walks through core JavaScript concepts for beginners, starting with callback hell, where deeply nested callbacks make asynchronous code hard to read and debug. It shows how Promises, chained with .then() and .catch(), flatten that structure, and how async/await offers a cleaner syntax built on top of Promises. The piece also contrasts synchronous and asynchronous execution, using setTimeout to illustrate how long-running tasks run without blocking the main thread. Finally, it covers hoisting, explaining how var declarations are initialized as undefined while let and const declarations throw errors if accessed before definition.

0
ProgrammingDEV Community ·

Linux kernel's task_struct: a guide to the process descriptor's fields

The task_struct is the C structure the Linux kernel uses to represent a single task, which can be either a process or a thread. Every running program has at least one of these, and it stores or links to the kernel's full knowledge of that task, including its state, identifiers, parent, memory, open files, signals and scheduling data. Defined in include/linux/sched.h and also known as the process descriptor, it has grown to a few hundred fields in modern kernels, many conditional on configuration options. Much of the heavy data is held in separate structures that the task_struct points to, and threads of the same program can share some of them. The author's post groups the important fields into sections, showing simplified listings and explaining each field's type, meaning and any older names used in 2.6-era kernels.

0
ProgrammingDEV Community ·

Keeping Proxmox NoVNC Consoles Working Behind HAProxy Using Sticky Sessions

Placing a Proxmox VE cluster behind a round-robin HAProxy load balancer can break NoVNC WebSocket console sessions, because requests get routed to different nodes mid-session. The author explains that this invalidates authentication tickets and causes WebSocket handshakes to fail. Rather than using a single backend or abandoning round-robin, the author chose to enable session persistence with HAProxy cookie-based sticky sessions. The article provides a full backend configuration that pins each browser session to one Proxmox node, including health checks and forwarded headers. According to the author, the console stays accessible even when an individual node goes offline for maintenance.

0
ProgrammingDEV Community ·

Phished Credit Controller's Mailbox Leaked Via Malicious App Consent, Not Password

In March, a credit controller at a company was emailed a link that led to a genuine Microsoft sign-in page. After signing in, she granted permission to an app called Remittance Viewer to read her mail, which it did daily for five weeks. The breach came to light when a builder received a fraudulent payment request that referenced accurate invoice details and a recent conversation. Resetting her password did not stop the access, because the app's permission persisted independently of it. The company revoked the app, tightened its tenant settings so users can only consent to low-risk apps from verified publishers, and removed 40 risky grants out of 212 found.