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

How does simple segregated storage pre-allocate lists of fixed block sizes?

I'm learning dynamic memory allocation, and still a little bit confusing with some details. We know that s segregated storage, is to maintain multiple free lists, where each list holds blocks that are ...
0
votes
0answers
22 views

How can I know which of my compilers calls which version of a specific library?

I have a library abc installed in various places of my computer which versions may differ. I also have different compilers comp1 and comp2. By executing the two following commands, I end up with two ...
0
votes
1answer
25 views

does using free() on a block always drop the mappings between its virtual memory and physical memory?

Let's say we want to allocate a block from the heap by using malloc. When allocating a a large size of memory, malloc calls mmap internally and for a small size allocation, malloc calls brk internally....
0
votes
1answer
30 views

malloc doesn't allocate contiguous virtual memory in the heap?

I realize that malloc calls mmap internally and pass NULL as the first argument to mmap so that the kernel will choose a suitable virtual address for the mapping, which means malloc will not ...
0
votes
1answer
37 views

how brk pointer grow after calling malloc

I'm new to Linux and C, just want to ask how brk pointer grow after calling malloc. We know that the kernel maintains a brk pointer that points to the top of the heap. let's say there is no available ...
0
votes
1answer
31 views

fork function flags each page in both processes as read-only? [closed]

I was reading a textbook which talks about how fork() work with virtual memory as: When the fork function is called by the current process, the kernel creates various data structures for the new ...
0
votes
2answers
47 views

Does every socket have its own buffers to send/receive messages?

I'm developping a C application that make extensive use of sockets. My doubt is: Does every socket that I create have its own buffers to send and/or receive messages from other sockets? In other words,...
2
votes
1answer
48 views

For a directory file descriptor dfd, can I prevent traversing up as in openat(dfd, “..”, …)?

I have a user $service with a directory /srv/$service/subdir. /srv/$service has a mode of 0700, i.e. it's only accessible by $service. That user can open a directory file descriptor to …/subdir or any ...
-1
votes
2answers
71 views

Why printf is not asyc signal safe function?

We know that printf is not async signal safe function. And below is my basic understanding: Let's say we have called printf in main method, so the content is written to stdio buffer, just before the ...
-3
votes
1answer
43 views

what does 'proc' in 'sigprocmask' mean?

I'm new to Linux and signals, sorry if my question sounds dumb, we know that Applications can explicitly block and unblock selected signals using the sigprocmask function, but what does 'proc' stand ...
1
vote
0answers
28 views

Theoretical question: Fetching a 32-bit variable from 128 bit addressable memory

Suppose I have a processor that is running Linux kernel, and the processor is connected with a 128 bit bus to a memory. The memory is addressed as one address gives you the full 128 bits of data ...
-1
votes
1answer
42 views

Does _start call my program's main function and other essential setup functions? [closed]

I'm reading a textbook which describes how loader works: When the loader runs, it copies chunks of the executable object file into the code and data segments. Next, the loader jumps to the program’s ...
-1
votes
0answers
20 views

does linker do relocations for functions that are referenced but not called? [closed]

I was told that: If your program references 10 functions in the library but calls 0 of them, the difference in lazy binding vs immediate binding is 0 vs 10 lookups. If your program references 100 ...
0
votes
1answer
39 views

why the dynamic linker couldn't resolve reference when a share library has a dependency on other share library?

below is my code: //a.c I don't use header files as this is just for demo purpose. extern void function_b(int num); void function_a(int num) { function_b(num) } //b.c void function_b(int num) ...
3
votes
2answers
80 views

how does dynamic linker resolve references in run time? [closed]

let's say I have a source file dll.c that use dlopen and dlsym functions to load a shared library called F.so in run time. dll.c has a reference to some_function(), and F.so has the definition of ...
0
votes
1answer
53 views

Programming - Communicating with chess engine stockfish / FIFOs / Bash redirections

I'm trying to write a little chess program - actually more of a chess GUI. The chess GUI should use the stockfish chess engine in the background when the player plays against the computer. I got ...
1
vote
1answer
26 views

What is the “thundering herd” problem and how can a race condition happen even after using spinlocks?

From here: wait_table A hash table of wait queues of processes waiting on a page to be freed. This is of importance to wait_on_page() and unlock_page(). While processes could all wait on one queue, ...
0
votes
0answers
24 views

Audacity sound not working

I get this error while trying to use audacity Expression 'ret' failed in 'src/hostapi/alsa/pa_linux_alsa.c', line: 1812 I've tried launching with env PULSE_LATENCY_MSEC=300 audacity with no luck
0
votes
1answer
58 views

Get Linux user password into a C program

I am trying to implement a PAM for Linux which gets invoked for sudo operations, the purpose of it is to ask the user for SMS sent to his mobile right after he enters a password when performing sudo ...
0
votes
1answer
33 views

How to avoid compatibility issue Segmentation fault (core dumped) with memory address

I am trying to hack the general C rules while research and try to store memory address in variable but my code failed with Segmentation fault (core dumped) when running under 64-bit system. And I know ...
0
votes
1answer
30 views

Xlib: Why am I having to close the display for mapping and unmapping windows?

// ... int main(int argc, char *argv[]) { int rev; Window win; Display *dis = XOpenDisplay(NULL); XGetInputFocus(dis, &win, &rev); XUnmapWindow(dis, win); XCloseDisplay(dis); /...
0
votes
0answers
27 views

execute mpi c program in linux

Nice people I get this error (I want to execute my MPI program) mpicc file.c -o obj /usr/bin/ld: /tmp/ccuTJy8E.o: reference to the undefined symbol "sqrt@@GLIBC_2.2.5" //lib/x86_64-linux-gnu/...
-1
votes
1answer
30 views

How to add 2 column values and find out percentage value?

When I do df, I get folowing results: Filesystem 1K-blocks Used Available Use% Mounted on udev 1529860 4 1529856 1% /dev tmpfs 308116 960 307156 1% ...
1
vote
0answers
24 views

Cannot read strings properly from GPS [closed]

I want to read only GPRMC but i can't read properly. here is the code. #include<stdio.h> #include<fcntl.h> #include<unistd.h> #include<termios.h> #include<string.h> char *...
0
votes
0answers
26 views

Latency in I2C communication Linux

I am trying to interface an IMU(BNO080) with Jetson Nano board(ARM cortex A57)(Linux 4.9) over I2C(at 400kHz clock). Communication goes well when setting up the configurations and getting the receipts ...
2
votes
2answers
639 views

How does piping affect stdin?

I want to write a C program, and I need to parse stdin. If I type cat file.txt | grep -v match, how does stdout from cat resolve with -v match? Are they concatenated? Are they two different strings? I ...
1
vote
1answer
87 views

How can we perform an arithmetic operation on a register using GDB? [closed]

I want to inject a bit-flip fault into a running program. For this purpose, I'm using gdb to insert a breakpoint into the target program and then flipping a single bit in a random-selected register. ...
0
votes
0answers
157 views

How to change clang-10, llvm-10, etc to clang, llvm, etc.?

I use Spacemacs, and installed llvm-10, clnag-10, clangd-10, and all related packages, in Debian 10. Used the following command to install llvm $ sudo bash -c "$(wget -O - https://apt.llvm.org/...
1
vote
1answer
37 views

How to handle read and write simultaneously in case of ttyUSB in linux C

I want to write application to interface with micro-controller with Linux PC through serial communication. I am able to write the read and write using basic C code using open, read and write function ...
0
votes
1answer
150 views

How to install libpq-dev on fedora?

I'm trying to install libpq-dev on fedora using the command below: sudo dnf install libpq-dev but the result is: No match for argument: libpq-dev Error: Unable to find a match: libpq-dev
0
votes
0answers
102 views

Undefined symbol when executing compiled binary, although readelf shows the symbol with the right version

I have compiled the vagrant-libvirt plugin following the instructions here: https://github.com/hashicorp/vagrant/issues/7039#issuecomment-488499883 It compiles fine, but at runtime I get the following ...
0
votes
0answers
22 views

Catch signal when a command fails

I'm trying to build a shell that gives you suggestions if you have a typing error, but I'm having trouble to catch the error. The user will type something and after parsing it, I will use the execvp() ...
0
votes
1answer
57 views

Buildroot compile error, librt.so: undefined reference to

I'm trying to compile a Buildroot image using a preconfigured builtin _defconfig file... More specific the riscv64_xwin_defconfig which is a simple setup for a riscv64 image with Xorg builtin. Since ...
1
vote
0answers
29 views

posix_spawn and sharing filedescriptors

I'm toying around with a side project where I want to have multiple processes share the same listening socket. In the linux documentation I read that posix_spawn will retain the filedescriptors so it ...
0
votes
1answer
147 views

Setting up DWM (Tiling Window Manager)

im trying to setup DWM, im able to successfully patch few patches, but there a couple things im not able figure out im using this on a laptop so i want to bind my volume, brightness, play pause keys ...
0
votes
0answers
30 views

missing SIGINT from script?

I am experiencing very strange behaviour when I attempt to send SIGINT from a bash script: #!/bin/bash ./executable 6 & PID=$! sleep 2 kill -s SIGINT $PID sleep 2 if wait $PID; then echo "...
1
vote
1answer
67 views

NCURSES SW runs in lxterminal, but doesn't run in a native Linux terminal [closed]

I wrote a "complex" C program using the ncurses library. It "correctly" runs in a lxterminal or gnome-terminal session; but doesn't run in a "native Linux terminal" session without X started (obtained ...
0
votes
0answers
22 views

Ceph RBD kernel module

Within ceph kernel client, I am looking for functions responsible for rbd block open/read/write operations. Since /drivers/block/rbd.c contains function rbd_open(), it looked as a suitable candidate ...
0
votes
0answers
20 views

Undefined reference to SDL functions in c for Conways Game of Life

I'm writing GameOfLife game in c with SDL2 but while compiling the files with CMake, it appears as an undefined reference to SDL functions: What can be the problem and how can I fix it? my ...
-1
votes
1answer
53 views

I just tried writting system() function using fork() and exec(). Is it a better method? [closed]

#include<stdio.h> #include<string.h> #include<unistd.h> #include<sys/types.h> #include<sys/wait.h> #include<error.h> #define size 30 char *get_command(int argc, ...
0
votes
1answer
63 views

Can UDP multicast listening socket receive unicast packet, OR, can UDP unicast socket receive multicast packet, on Linux IPv4 stack?

My understanding is this, if a socket does not bind local address(or binds to INADDR_ANY), and does not call connect() to set remote address/port, then there is no way to prevent unicast packets to be ...
1
vote
1answer
32 views

How can I use fork to calculate partial results of a calculation?

The task that has been given to me is that I have to find all numbers that divide a number (let's call it x) and find out how many times does it divide it. I have to use fork to do the task. What I ...
0
votes
0answers
17 views

Verifying a self signed openssl signature

I have a self signed openssl certificate on my embedded device, only this embeded device has access to the private key which signed the certificate and the certificate is as follows : Certificate: ...
0
votes
0answers
9 views

Using POPEN to find executable file with a given command (Client - server)

The client sends an UNIX command to the server, the command is read from an input.dat file. The server has to examine the paths stored in the $PATH variable, and sends back to the client those paths, ...
0
votes
2answers
29 views

How to execute recursively a program on every files contained in directory with find

I wrote an executable that I want to execute on all the files contained in a directory. This is what the program looks like: #include <stdio.h> #include <stdlib.h> #include <sys/types....
0
votes
1answer
137 views

Can't find the source of some “asm”, “generated” header files in linux kernel?

So, I am writing a module, that is working in kernel space. My code compiles correctly and works correctly. The thing is that there are some header files, which I couldn't find anywhere. That doesn't ...
0
votes
1answer
43 views

File descriptors of executable binary file and shared libraries in /proc/PID/fd?

Do user processes keep a file descriptor for the executable file itself, and for shared libraries? For example, if I look into /proc/PID/fd of bash, I expected to see at least the following fds, ...
1
vote
0answers
87 views

ps command output, WCHAN column '-' for all processes

ps axo ppid,pid,stat,wchan,cmd outputs - for the WCHAN column for all processes, including the ones in sleep, on Debian bullseye, did I do something wrong? BTW, wchan shows 'the kernel function in ...
1
vote
1answer
25 views

Recurrent output of printf() to stdout each time fork() is invoked allthough printf() is invoked prior to fork(). And why does '\n' fixes this? [duplicate]

While I was playing around with fork() I noticed a rather strange behavior but I couldn't figure out myself why this happens. In the example below, each time fork() is invoked the output from the ...
1
vote
1answer
56 views

Are there any alternatives to ltrace that does the same job?

ltrace doesn't work on binaries linked with the -z now option—Check this question—which is the default on my Ubuntu 19.10 system. It only works on binaries linked with -z lazy. Is there any ...

1
2 3 4 5
14