2022 Developer Survey is open! Take survey.

Questions tagged [c]

C is a general-purpose computer programming language used for operating systems, games and other high performance work and is clearly distinct from C++. It was developed in 1972 by Dennis Ritchie for use with the Unix operating system.

Filter by
Sorted by
Tagged with
2 votes
1 answer
48 views

Optionally compile translation unit makefile

I'm writing a program in c and I want to optionally compile a translationunit based on whether the user wants to or not. Basically I have two files, one main.c which should always be compiled. ...
user avatar
-1 votes
1 answer
90 views

Why does the Linux kernel not use rust?

I have heard that the Linux Kernel uses rust. I don't know much about the programming language except that it has the potential to run faster than C. According to websites Rust is more safe than C ...
user avatar
0 votes
0 answers
26 views

errno vs errors returned by library functions [migrated]

For errno, there are a bunch of library functions, like strerror(), etc. to convert or print the error code. But what about the error codes returned by library functions? E.g. write() will return ...
user avatar
  • 411
0 votes
1 answer
28 views

sscanf equivalent in shell script

I have a file which has some stats and counters stored for some ACL rules. I want to design a shell script to read that file and parse those counters. I have done the similar thing in c programming ...
user avatar
  • 131
0 votes
2 answers
47 views

Signals table in /proc/[PID]

I am trying to overwrite or change the Signals of a process. As I guess there is a table of signals in every process separately. Is there anything like that in the /proc folder? Thank you for your ...
user avatar
0 votes
1 answer
17 views

Why posix_memalign function requires sizeof(void *) in alignment?

In the posix_memalign() man page, it is written that alignment argument should be power of two and a multiple of sizeof(void *). A similar program memalign() requires the alignment argument only to be ...
user avatar
  • 21
1 vote
1 answer
74 views

Why malloc allocates more memory than neeed?

While working with malloc() and sbrk() I found that the malloc() function always allocates minimum of 135168 bytes even if 1 byte is requested. Why malloc() allocates so much memory ? I can allocate 4 ...
user avatar
  • 21
0 votes
0 answers
26 views

What's the best way to embed a terminal emulator into my (ncurses) app

Ideally, this would be in the form of a library that gives access to a buffer of characters to display and allows injecting characters and signals via an or character stream. I am open to creating ...
user avatar
0 votes
1 answer
46 views

A simple global keyboard shortcut handler

Yeah, I know there's actkbd which allows to assign global keyboard shortcuts which will work everywhere including the text console and a graphical session but I don't want to run an extra daemon (long ...
user avatar
0 votes
0 answers
89 views

Why is unistd.h named the way it is?

Similar in spirit to this question about the etymology of linux commands, I'm curious about the origin of the name of unistd.h. From the Open Group's description of unistd.h (emphasis mine): unistd.h ...
user avatar
0 votes
0 answers
18 views

A Linux service that always kills the last- but not the first

I'm running Armbian (Debian) and am using this openvfd driver to control a 7-segment LCD on the front of my device. I made some pretty significant edits to the code in order to allow writing custom ...
user avatar
-3 votes
1 answer
49 views

What is BusyBox?

Just wondering what BusyBox is used for and if I can use it for my project. I have seen the Philips Hue Bridge runs BusyBox and I would like to use it on a relatively small, but powerful controller, ...
user avatar
1 vote
1 answer
44 views

Is there a way to change GTK theme for one session in ANY desktop environment?

When I search for a way to change the gtk theme in Linux, I find that there is a different way to do it for every desktop environment. The only one I found that worked on all desktop environments was ...
user avatar
4 votes
1 answer
457 views

How does the fork system call work?

If we look at the example #include <stdio.h> #include <unistd.h> void main(){ int pi_d ; int pid ; pi_d = fork(); if(pi_d == 0){ printf("Child Process B:\npid :%d\nppid:%...
user avatar
  • 529
0 votes
1 answer
30 views

How do `nm` choose the character to print for each symbol type?

I'm currently doing a nm like program, to print the symbols of an ELF file with their addresses and their type. The typical output is something like : $ nm ./my_exec 0000000000003d28 d _DYNAMIC ...
user avatar
  • 11
0 votes
3 answers
271 views

Closing different ends in a pipe

I have wrote the following code for IPC using pipe() : #include <unistd.h> #include <stdio.h> #include <sys/wait.h> int main(void) { char message_buffer[15] = "...
user avatar
  • 87
0 votes
1 answer
69 views

execlp "sort" with input from pipe stucks, why?

sort is waiting, but what? I tried execlp("head", "head", "-n", "3", NULL); instead sort and it works fine. #include <stdlib.h> #include <sys/wait.h&...
user avatar
  • 3
0 votes
0 answers
53 views

How to get Gentoo Package Count with C Code?

I have a terminal fetching program on my GitHub that is similar to Neofetch but it is written in C instead of bash called Cfetch I know how to get the package count for Arch with C: static char *...
user avatar
1 vote
0 answers
23 views

File locking from different therads of the same process, including for Solaris OS

I need to perform a file lock when accessing a file from C/C++ code with the following requirements: Blocking should be performed when access occurs not only from different processes, but also from ...
user avatar
  • 205
0 votes
0 answers
12 views

Writing, forking and writing to the same file descriptor duplicates the first message [duplicate]

I'm writing a program in python for a linux computer. I write to a file, fork, then write again to the file in the child process, the first message is duplicated! MVCE: import os f = open("/tmp/...
user avatar
  • 391
1 vote
0 answers
41 views

What is the proper way to check whether stdout was deleted

I need to check from a running C program whether stdout was deleted. By "deleted" I mean a situation when in /proc/pid/fd is written "deleted": ll /proc/91495/fd total 0 dr-x------ ...
user avatar
  • 205
0 votes
0 answers
42 views

Undefined reference to 'fminf' while using Code Runner on Visual Studio Code

I am a fresh Linux user (Linux Mint 20.3), and I am trying to set up my C code environment in Visual Studio Code. On my Windows PC, I am able to run my code with no problems. Yet here, when I run my ...
user avatar
1 vote
1 answer
35 views

seeking example source code for GTK4 sourceview editor

To port Bismon to GTK4, I need examples of working GTK4 source handling multi-font text, keypresses, etc. This is for Linux/x96-64 only And Bismon is GPLv3+ licensed (some kind of static source code ...
user avatar
1 vote
1 answer
95 views

Replace HID device driver with custom one

I'm looking for a way to replace my keyboard kernel module to a custom one. I have a Logitech MK710 keyboard + mouse set for this purpose, with a USB receiver with those 2 interfaces. Automatically, ...
user avatar
0 votes
1 answer
309 views

How does a process and its children use memory in case of mmap()?

Let's say, we are creating a shared memory using mmap(). Let's say the total memory size is 4096. If we use a fork() system call to create children, would the children use the same memory, or will ...
user avatar
2 votes
2 answers
229 views

Which signal (like SIGINT or SIGTERM) can a process get when system is going to reboot?

My application needs to do something before exit, I have already handled the ctrl-c case by handling signal of SIGINT, but I'd also like to handle the case when the system is going to reboot. I ...
user avatar
  • 133
0 votes
1 answer
89 views

error: 'struct msghdr' has no member named 'msg_accrights' is the message while compiling C program [closed]

Migrating from Sun Solaris to RHEL. But while compiling the C program getting the following errors. struct msghdr msg; msg.msg_accrights = (caddr_t)&fd_to_send; msg.msg_accrightslen = ...
user avatar
  • 1
0 votes
0 answers
18 views

Identical .so shared libraries (with no symbols) are generated when compiling different C source files

At the institution I work for we have a User Exit made in Pro*C (SQL embedded in C language). We are having some troubles because identical shared libraries are generated when compiling different ...
user avatar
0 votes
2 answers
69 views

C language programs not workning on ubuntu

I wrote a simple code to find even and odd numbers in c. #include <stdio.h> int main() { int num; printf("Enter an integer: "); scanf(" %d", &num); (num % 2 =...
user avatar
0 votes
1 answer
80 views

How do I write directly to video memory without xorg?

Kind of an odd question I know, but fifteen years ago I was able to use svgalib on some ancient version of Debian to draw directly to video memory without xorg. To my dismay I see svgalib was pulled ...
user avatar
  • 331
1 vote
1 answer
60 views

can I do isatty() without opening the file

On Linux, Is it possible to do the equivalent of isatty(fd) given a path, and without using open()? I found that I cat stat() the path to determine that it is a character device. Next, I can take the ...
user avatar
  • 1,081
0 votes
0 answers
45 views

How to identify if a filepath is remote(network) or on removable media

I have a C application which needs to check if a given filepath is local or remote/removable media. I found an answer here which suggests using statfs. But it won't tell me if it is on USB Plus, the ...
user avatar
  • 111
1 vote
1 answer
148 views

socat: EXEC does not relay correctly

I have a small program that first outputs a string to the user and then takes an input. I instead want the program to work by sending and receiving from a port. To try to realize this I ran the ...
user avatar
0 votes
1 answer
28 views

FreeCiv will not build because of an error against curl

I am currently trying to build FreeCiv. But I am unable to do so. The error says that there are many commands used that are undefined references when using Curl commands. I sadly could not get a copy ...
user avatar
  • 1
0 votes
1 answer
191 views

how fork() can return multiple values? [duplicate]

How does the fork() function return different values in parent process and child process? Assume there is no write operation in parent process and its child process.
user avatar
0 votes
0 answers
209 views

Using wayland protocols to implement an On-Screen-Keyboard

I wrote a small test app which tries to write an emoji to a window of a different app. But it just keeps freezing in certain situations (or always in the case of gnome) and now i'm wondering if input-...
user avatar
  • 1
0 votes
0 answers
186 views

How to get vid and pid of usb device before authorize it

I am writing an application in C++ on Linux (Ubuntu) that can detect plugging USB devices. I am using libudev library to detect new devices and get some pieces of information about them, such name, ...
user avatar
0 votes
1 answer
121 views

settimeofday function can't change time

In Ubuntu 20.04 LTS, I write a program using C to change the system time. During the execution of the program, it does output the modified time using commands date and hwclock. But when the program ...
user avatar
0 votes
1 answer
62 views

Creating Kernel Module

I am currently reading a book on Linux Kernel Module Programming - https://tldp.org/LDP/lkmpg/2.4/lkmpg.pdf and I am running into a compilation error when running make. /* hello.c − The simplest ...
user avatar
0 votes
1 answer
98 views

Creating LKM using Makefile

As of lately, I have decided to begin learning about OS kernels and came across a few resources to aid in my learning process. Following the tutorial, I setup an Loadable Kernel Module and Makefile, ...
user avatar
0 votes
1 answer
235 views

get system UUID from C code?

I am trying to get system UUID from C program, I tried the following: #include <stdio.h> #include <stdlib.h> #include <string.h> #define SYS_UUID_PATH "/sys/class/dmi/id/...
user avatar
2 votes
1 answer
513 views

Why are `copy_from_user()` and `copy_to_user()` needed, when the kernel is mapped into the same virtual address space as the process itself?

Why are copy_from_user() and copy_to_user() needed, when the kernel is mapped into the same virtual address space as the process itself? Having developed a few (toy) kernel modules for learning ...
user avatar
  • 3,317
0 votes
1 answer
54 views

What determines how files are ordered when using ls without sort?

The order when using ls with -U flag is the same order that I get when using dirent.h library in C and display file names in a loop. When I display d_off member of the dirent struct the numbers appear ...
user avatar
  • 3
0 votes
0 answers
50 views

Can't receive CTR-C after changing process group

I have this code: static void signal_handler(int signum); int main(void) { const struct sigaction sa = { .sa_handler = signal_handler, }; sigaction(SIGINT, &sa, NULL); ...
user avatar
0 votes
1 answer
120 views

Reading in a copy of `/usr/share/dict/words` is 10x slower than the file itself

I was experimenting with dictionary implementations in C and found /usr/share/dict/words to be a pretty good file for testing. For whatever reason, I wanted to make a copy of the words file into my ...
user avatar
0 votes
0 answers
20 views

Getting nmcli to work with g_spawn command

Working on a simple gtk c project and I’m needing a nmcli command which would be easy to trigger using the g_spawn_command_line_sync command but it doesn’t work. For some reason g_spawn doesn’t ...
user avatar
1 vote
2 answers
165 views

Write in /dev/mem without using mmap

It is possible to write on /dev/mem without using mmap? I'm enabling pull-up resistors on a Raspberry Pi inside an LKM and the function void *mmap (caddr_t addr, size_t len, int prot, int flags, int ...
user avatar
0 votes
0 answers
34 views

Executable doesn't run on boot-up when changed to write the logs to a file

I am running an executable on boot-up, and the executable prints logs via printf to the console and when the service runs, I see the binary running in the output of ps but no longers are printed to ...
user avatar
  • 21
0 votes
1 answer
112 views

How to determine FFTW version?

The C library FFTW ("Fastest Fourier Transform in the West") provides subroutines for calculating discrete Fourier transforms (DFTs). How do I determine what version of FFTW I have on my ...
user avatar
  • 14.3k
1 vote
1 answer
311 views

Allocating 8MB physically contiguous memory in Linux

Can I allocate more than 4MB physically contiguous memory without enabling CONFIG_CMA kernel config parameter? Currently, I am using dma_alloc_coherent() call, but it fails if I try to allocate a ...
user avatar

1
2 3 4 5
16