Skip to main content

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
0 votes
0 answers
7 views

define an array in c using a macro as length in C [migrated]

I want to defined an array, the length from a macro as below, #define A (2.5) #define B (2.0) #define LEN (A*B) // I know LEN is an integer, not decimal numbers static int array[LEN] // define ...
Keely Darien's user avatar
3 votes
2 answers
92 views

Is it possible for SIGALRM to be delivered after setitimer() disables the timer?

I have some code like this that has failed once on CI and once locally, though I cannot reproduce it reliably. The code is like this: #include <stddef.h> #include <signal.h> #include <...
Tavian Barnes's user avatar
2 votes
2 answers
2k views

Why is off_t signed?

On my journey to create a 16 EiB sized file, I encountered the following issue: POSIX defines files to have their size represented using type off_t, and that "blkcnt_t and off_t shall be signed ...
Semnodime's user avatar
  • 377
0 votes
0 answers
19 views

swupdate and target image size

I try to use swupdate to update my system. My swu file is pretty simple software = { ...
Alex Hoppus's user avatar
8 votes
1 answer
1k views

Does mtrace() still work in modern distros?

tldr: Does mtrace still work or am I just doing it wrong? I was attempting to use mtrace and have been unable to get it to write data to a file. I followed the instructions in man 3 mtrace: t_mtrace.c:...
TopherIsSwell's user avatar
0 votes
0 answers
35 views

File descriptors get corrupted when program runs in background

I have written a program for an embedded Linux system(petalinux). It runs fine when started from the terminal or TCF debugger. However, I want it to run when the system starts, so I use the start-stop-...
user3219624's user avatar
1 vote
1 answer
134 views

Where do i trace NVME IO within the Linux driver?

I want to write a small Linux driver extension. More specific: I want to write all the communication between the host and a M.2-nvme-ssd into a userspace file. The nvme driver is pretty big though and ...
led's user avatar
  • 13
0 votes
0 answers
26 views

Does bash explicitly allow commands like passwd, su, etc., to run in setuid while disabling other custom binaries? [duplicate]

I know that /bin/bash has certain built-in protections that prevent the abuse of the Set-UID mechanism. So if I create a custom binary and execute it, it won't run with SUID 0 (refer the below image). ...
yellowspectre's user avatar
0 votes
0 answers
118 views

How to keep a shell alive after it gets started from inside a program?

I was not sure where to ask this question, since it is a mix of both programming and Linux, but hopefully this is the right place. I have written a simple program, which I'm buffer overflowing. I have ...
r3k0j's user avatar
  • 15
0 votes
0 answers
25 views

Impact of using SHM_HUGE_1GB for a size much smaller than 1GB (say, 64MB)

I'm relatively new to actually using (not understanding) a shared memory in Linux. I'm dealing with the situation now where I need to allocate a contiguous chunk of shared 64MB memory. While picking ...
Gwangmu Lee's user avatar
0 votes
0 answers
13 views

I'm trying to create a new nv_uboot-snow-usb.kpart file changing some parameters on the file snow.h file,but the modifications I made don't stick

My ARM Chromebook SNOW has the mmc slot broken,but I've realized that I can boot Linux using the USB port.To enable the booting of Linux via USB I have modified this file : https://github.com/...
Marietto's user avatar
  • 549
0 votes
0 answers
55 views

What safety CFLAGS does the Linux kernel use?

I have seen it said that the Linux kernel is built with -fwrapv to define signed integer overflow as wraparound, potentially sacrificing a tiny bit of performance in return for preventing the ...
rwallace's user avatar
  • 101
0 votes
1 answer
96 views

Help with Makefile for C program

I'm trying to generate a new library that includes another one I have created previously. In my current folder I have my source files inside a src folder and my headers inside an include folder. This ...
Ricardo Sisco's user avatar
38 votes
3 answers
7k views

Single '#' in old C files

I started studying old C code (Unix v6) and I'm wondering what is the purpose of a single # in the beginning of the .c file. For example from https://github.com/lsahn-gh/unix-v6/blob/master/sys%2Fken%...
g0mb4's user avatar
  • 701
9 votes
5 answers
2k views

Print all C comments to a separate text file

I would like to print all my C comments to a separate text file. Using awk, sed, grep, or bash output all multi-line C comments between /* ... */ (inclusive) output lines with // comments Optional: ...
jwzumwalt's user avatar
  • 269
0 votes
1 answer
69 views

compile error with tiny http server c code gcc debian

My distro is MX Linux (Debian) GCC was already installed with distro. I am trying to compile some open source code from Nir Lictman. His Minimalist C web server code compiles in his YouTube video. ...
xstack's user avatar
  • 105
0 votes
3 answers
241 views

Making changes to the shared library

Suppose we have a C program that uses the shared library. If you make changes to a shared library and rebuild it, all programs using that library will automatically receive those changes the next time ...
dsa14dfS's user avatar
0 votes
0 answers
65 views

How do I identify the connected USB device?

If I write the rules, for example, in this form: ACTION=="remove", GOTO="serial_end" SUBSYSTEM!="tty", GOTO="serial_end" KERNEL=="ttyUSB[0-9]*", RUN+=...
alexanderzhirov's user avatar
1 vote
1 answer
250 views

Reboot command doesn't invoke reboot system call?

OS is Debian. As per my question here: Is there a way to determine what process is rebooting a server? I wrote a kernel module to intercept the reboot syscall via modifying the syscall table. ...
cat pants's user avatar
  • 487
0 votes
0 answers
53 views

Makefile with Automatic Dependency Generation

I am going crazy, please can someone help... I want: .c files in src .h files in include .o files in build .d files in build binary executables in bin I have taken inspiration from the OSDev wiki, I ...
wjcblair's user avatar
0 votes
1 answer
109 views

Why is MB_CUR_MAX 6 instead of 4 for UTF-8? (Linux, glibc)

MB_CUR_MAX is defined by glibc as 'a positive integer expression that is the maximum number of bytes in a multibyte character in the current locale.' If I print the value I get 1. I assume that this ...
Sebastian Carlos's user avatar
0 votes
0 answers
27 views

SocketCAN how can I get result of the operation

Is it possible to get the status of the CAN operation? Example operation: write(socket, &frame, sizeof(frame)); Is it possible to check if the frame was ACK-ed or get any other CAN status ...
0___________'s user avatar
3 votes
2 answers
138 views

Creating a filename for an opened file descriptor

I have a file on the filesystem. I'm opening the file with the open(2) function to get the file descriptor to that file. Now I remove the file. But I still have the file descriptor, so I can read and ...
antekone's user avatar
  • 702
0 votes
0 answers
42 views

cc linker error

I'm writing a C application based on GTKlibrary on Debian 12. The program is build by a Makefile, generated from cmake. The compile phase of the source files is correct but when the linker is fired I ...
SteMMo's user avatar
  • 197
0 votes
0 answers
35 views

Can't Pipe Into Grep Using unistd

I'm trying to write a shell with IO piping, and I noticed that the program would fail specifically when piping into grep. Here's some code outlining my piping technique: #include <unistd.h> #...
Vance Raiti's user avatar
0 votes
1 answer
303 views

How do I increase /proc/sys/fs/mqueue/msgsize_max to more than 8192?

Is it possible to change the default value to be larger? when i try to use it in a C program it fails on values larger than 8192. printf("create queue size: %lu\n", attr->mq_msgsize); ...
meanthatmuchtoyou's user avatar
0 votes
0 answers
45 views

Using Terminal with a serial connection

Hello I am using terminal to output my serial connection device. I was wondering how can I get rid of the spaces when it starts a new line. On Windows I would use Putty and turn on Implicit CR in ...
David Duong's user avatar
0 votes
0 answers
256 views

ld error with clangs when compiling vdso

i am trying to compile a kernel but it always return this error: LD arch/arm64/kernel/vdso/built-in.o ld.lld: error: cannot find linker script -r make[2]: *** [scripts/Makefile.build:507: arch/...
xxjoe's user avatar
  • 11
2 votes
0 answers
563 views

Why do_exit() undefined?

I was building a kernel module for trying kthreads. A thread function after doing its works exits by calling do_exit(0). But when I am trying to compile the module, it is showing the error that ...
arka's user avatar
  • 253
0 votes
0 answers
105 views

Memory protection keys: Exception handler crashes if pkey0 is write-disabled

Background: in-process isolation based on memory protection domains in x86/linux using memory protection keys (MPK) and the protection key register PKRU. Setup: The program first executes ...
Robert Kueffner's user avatar
0 votes
1 answer
570 views

gdb print out a pointer is null or not

source:https://git.postgresql.org/cgit/postgresql.git/tree/src/backend/optimizer/plan/planner.c (gdb) n 3556 if (root->group_pathkeys) (gdb) s 3558 else if (root->...
jian's user avatar
  • 577
0 votes
1 answer
56 views

Why does netstat show my socket tutorial program having a port of "x11-1" instead of the port I set in code?

I am trying to learn about socket programming, and I have the following function to set up a socket: 29 int CreatePassiveSock(char *protocol, char *portstr, int qlen) { 30 ...
Anthony De Vellis's user avatar
0 votes
0 answers
21 views

Unable to open a file for writing which has write permisions [duplicate]

There is a regular file file in the /tmp directory with write permissions -rw--w--w- 1 user1 user1 /tmp/file When I try to open this file as a user (I run the code after su user2) who is not the owner ...
ibse's user avatar
  • 341
1 vote
1 answer
254 views

What tells make that a file is an intermediate file (and can be auto removed)?

I'm simply studying make. And I stumble upon the question on make's autoremoving intermediate file. I'd like to better predict how make would mark file intermediate (i.e. answer "Would auto ...
Koala Yeung's user avatar
3 votes
2 answers
317 views

What is the region of memory allocated by malloc()?

I was writing a multi-threaded C program using pthread library. The program calls the malloc() from a thread and the main-thread. When I inspected the memory address returned by malloc(), the address ...
arka's user avatar
  • 253
1 vote
2 answers
136 views

How can pwrite protect against overwriting data?

Assume we have two processes A & B. they both want to append to the same file. both opened the file with open (without O_APPEND) function and they are using pwrite(fd, buf, bytes, offset) to write ...
Myonaiz's user avatar
  • 113
0 votes
1 answer
720 views

Modpost: "module … uses symbol … from namespace …" error porting FL2000_DRM driver to newer version

I'm trying to port https://github.com/kenballus/fl2000_drm_519, designed for linux 5.19, to linux 6.2.11, but after applying the patches attached below, I'm getting this error and I don't know how to ...
alonely0's user avatar
5 votes
1 answer
216 views

Is there a *BSD equivalent of MacOS renameatx_np, atomic swap file renaming?

I am looking to create a *BSD compatible C function like the one below: int fs_ext__swap (const char *from, const char *to) { int res = renameatx_np(AT_FDCWD, from, AT_FDCWD, to, RENAME_SWAP); ...
Lee's user avatar
  • 519
1 vote
0 answers
61 views

PTRACE_PEEKTEXT ptrace: Input/ouput error

I try to read the values from memory with using PTRACE_PEEKDATA. To find the memory address of specific line I am using with objdump - objdump --dwarf=decodedline ./exe_filename and got the output: ...
Aviel15's user avatar
  • 11
0 votes
2 answers
186 views

Program starts from rc.local but doesn't do anything

I have a program which uses msqllib. It scans some hardware that I build and then updates a mysql database. This program has been running for a number of years but I have never been able to autostart ...
Nigel W Johnson's user avatar
0 votes
1 answer
77 views

Virtual keyboard using UHID

I am trying to achieve what the QMK firmware does for keyboards but using software. So, I would like to turn off keys, substitute some keys for others, layers and etc. The first thing that appeared ...
Henrique Hott's user avatar
0 votes
2 answers
207 views

Measuring execution time of BASH and custom shell

I have written simple shell in C with job control and piping/redirection functionality. How can I compare execution time(real,user and sys) of this shell with BASH ? I tried to measure time of ...
Marko Brodanac's user avatar
1 vote
0 answers
187 views

Linux TCP/IP kernel stack and VFS interaction

I'm reading the Linux kernel implementation of the TCP/IP stack. Everything was ok till I encounter this figure while reading TCP/IP architecture, design and implementation in Linux As you may see ...
ca-hercor's user avatar
1 vote
2 answers
1k views

Why all output of my C program directed to stdout is sent to journald?

I work on yocto based linux distribution. I'm no expert on systemd and neither on systemd-journald. My C program my_c_program is started at boot by the script my_script.sh. Below there is the file ...
User051209's user avatar
1 vote
2 answers
180 views

grep -c "string" file.txt if "string" continues on next line?

As the title says, I am trying to count the instances of a string in a text file. However, in some instances, the string continues onto the next line. How can I alter this simple code to find the ...
zaPIRATEne's user avatar
3 votes
2 answers
674 views

Can you compile a file without writing to disk?

I'd like to compile some code from within a C/C++ program. Here's how it would work. I would have a buffer in memory (dynamically allocated) that contains ASCII text that constitutes C code. From my C/...
Isaac D. Cohen's user avatar
2 votes
0 answers
118 views

What's the difference between ftrace and blktrace tracepoints?

For instance, we have /sys/kernel/debug/tracing/events/block/block_bio_complete and block_rq_complete which is basically IO completion trace points for ftrace, I believe. Using sudo blktrace -d /dev/...
Ken Y-N's user avatar
  • 253
0 votes
1 answer
201 views

Using IPC_CREAT with an already created shared memory segment

I am trying to figure out what will happen if I use the IPC_CREAT flag with shmget(). I have used a key of an already created shared memory segment from another process. When I did so, the calling ...
John adams's user avatar
1 vote
0 answers
3k views

Compiling CFLAGS in a Yocto Recipe File

Issue: I have 2 macros I added in a c file and I have 2 machines. Using Yocto recipe I wish to build the code with specific macros for specific machines. Breaking down the issue in sub parts - hello.c ...
Nathan's user avatar
  • 21
0 votes
1 answer
371 views

shmget() and shmat()

Using shmget(), we can allocate a shared memory block of certain size in bytes and using shmat(), we attach this shared memory block to the address space of the calling process. I need to check my ...
John adams's user avatar

1
2 3 4 5
18