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
2answers
29 views

Communication between two file descriptors (clients)

I am following this document I struggle to wrap my head around file descriptors and how I could read data from one, process it and then send to another. As a server I need to be able to accept ...
1
vote
0answers
13 views

How to make the php extension(.so) file portable with dependent libraries?

I need to make an php extension(.so) file which can be made portable. The created library works fine on one of my machines, but, when I send it to other machine, it does not load properly as a ...
0
votes
0answers
49 views

__VA_ARGS__ does not accept NULL [on hold]

I want to use the following code #include <stdio.h> #define my_fprintf(arg1, ...) fprintf(arg1, __VA_ARGS__) int main() { my_fprintf(stderr, NULL); return 0; } but the following ...
0
votes
0answers
25 views

How does calling a function from a shared library work?

So you load a shared library right before runtime, and add the symbols (i.e. functions) it provides to a global offset table. What happens when you call a function it provides? Because you already ...
1
vote
1answer
56 views

Linux ioctl VT_GETSTATE fails if process is run manually

I'm using the ioctl syscall on Linux to get the current tty in a C program. I don't know why the ioctl fails if the program is run manually (as root) while it works as expected if the init.d script ...
0
votes
0answers
8 views

How does glibc's ptmalloc2 determine if small freed heap allocations (<= 88B) are put in fast or small bins?

How does glibc's ptmalloc2 determine if small freed heap allocations (<= 88B) are put in fast or small bins? I'm trying to understand how the glibc ptmalloc2 heap allocator works, and so have ...
1
vote
1answer
24 views

Will a USB drive be mounted by the time a udev monitor in C receives a signal?

I'm using libudev to detect when a USB drive is attached in a C program. Once I detect that it has been attached via a signal from the kernel (through a udev_monitor structure), can I assume that ...
0
votes
1answer
16 views

How KDE Konsole handle a SIGTERM?

I have a particular setup : One manager program can launch and stop program One wrapper program which is composed of: Konsole one program worker running into Konsole My problem is: When manager ...
1
vote
1answer
72 views

Exploit SUID program by using environment variables

Suppose I have a vulnerable SUID program belonging to the user Bob, which is executable by all users. #include <stdio.h> #include <stdlib.h> #include <string.h> int main(int argc, ...
3
votes
2answers
1k views

Bash shell launched by forkpty() spawns child processes that ignore SIGINT. Why and how do I ensure SIGINT is not ignored?

I have a C program that uses forkpty to execute a bash shell. I'm finding that the programs launched by this shell are launched with SIGINT ignored, so when I send a Ctrl-C to the shell they never ...
0
votes
1answer
50 views

Why below code is not able to unblock SIGINT signal

I am trying my hand on Linux Signals. Where I have created a scenario mentioned below: Intially block all SIGINT signals using sigprocmask(). If sender send SIGUSR1 signal then unblock SIGINT for ...
-1
votes
1answer
50 views

How to break down signal system call prototype in Linux?

I am reading "The Linux Programming Interface", where I find signal system call prototype as stated: #include <signal.h> void ( *signal(int sig, void (*handler)(int)) ) (int); What is signal ...
0
votes
2answers
44 views

Retrieve USB device information for drive which provides specific mount point

I am writing a C/C++ tool which needs to do the following: Detect when a new mount point has been mounted. ✔ Find out which (USB) device provides this mount point. ❓ Get the USB vendor ID and product ...
-1
votes
2answers
66 views

Are 'kernel-modules' and 'GNU C Library' the same?

I am newbie in Linux and I am trying to understand the basics of the Linux OS structure. So: Are the 'linux-kernel-modules' listed in the output from 'lsmod' and 'GNU C Library' (about 2000 ...
3
votes
1answer
2k views

ioctl: invalid argument for HDIO_GET_IDENTITY

I wrote a program to get the details of hard disk drive using HDIO_ ioctl calls. For writing program, I'm referring Documentation/ioctl/hdio.txt in kernel source(2.6.32). Here is my main part of ...
22
votes
2answers
3k views

Does POSIX guarantee the paths to any standard utilities?

From C, what's the easiest way to run a standard utility (e.g., ps) and no other? Does POSIX guarantee that, for example, a standard ps is in /bin/ps or should I reset the PATH environment variable ...
3
votes
2answers
969 views

What is the advantage of archiving C object files in a static library (.a file)?

I mean, as opposed to just linking to individual modules/object files. Why are groups of modules archived together? Doesn't it make the executable 1. larger, and 2. less secure (i.e. more vulnerable ...
0
votes
0answers
15 views

How to measure the resource use of a system call?

I've written two system calls, and want to compare the memory used up by each one. How could I go about doing this? I've tried getrusage, but almost all of the fields are 0. Thank you!
1
vote
1answer
26 views

Why blocking read() on a pty returns when process on the other end dies?

When slave side of pty is not opened, strace on the process, which does read(master_fd, &byte, 1);, shows this: read(3, So, when nobody is connected to the slave side of pty, read() waits for ...
0
votes
1answer
25 views

Check the actual glibc version used

I want check the glibc version used by toolchain to build code for the target system (ARM). In toolchain directory I tried strings /sysroot/lib/libc.so.6 | grep GLIBC the output is GLIBC_2.4 ...
0
votes
1answer
127 views

How to find definitions in standard librarys using the gcc preprocessor?

I have found in my project a type definition, which is definitely from a standard library. Lets say the definition is called uint64_t . I would like to know, what definition is exactly behind that ...
1
vote
0answers
24 views

Do inotify watches automatically stop when a program ends?

Per man 7 inotify, there are a limited number of inotify instances (/proc/sys/fs/inotify/max_user_instances) and watches (/proc/sys/fs/inotify/max_user_watches). If inotify is set up using ...
0
votes
1answer
47 views

strace does not list /etc/hosts in ping/host command in CentOS 7

I was reading https://zwischenzugs.com/2018/06/08/anatomy-of-a-linux-dns-lookup-part-i/ and on the author's Debian/Ubuntu system /etc/hosts is used. But when I do strace under CentOS 7, I don't see ...
1
vote
1answer
45 views

Preprocessing a C header file

I have a large header file which has many sections that are included or omitted depending on whether certain names are defined in the file. For example lines like- \#define A \#define B 2 ... \#ifdef ...
1
vote
0answers
25 views

inotify stops reporting events

I am using inotify in a program written in C; it closely follows the example in man 7 inotify. The steps are essentially: /* setup */ int fd = inotify_init1(IN_NONBLOCK); int wd = inotify_add_watch(...
0
votes
1answer
76 views

Restrict child process 's cpu and ram usage by parent process using C/C++ in Linux

I am trying to create child processes from parent processes.I want to restrict CPU and RAM usage of the child processes using C/C++.Is there is a way to do it?
0
votes
1answer
74 views

Bash parallel processes have turned off the system?

I have a remote controlling server which I use to automatically executing commands/scripts etc to all my nodes in series. To increase the performance and speed I wanted to run it in parallel. I am ...
1
vote
0answers
46 views

Howto provide user access to /sys/class/backlight/acpi_video0/brightness programatically (udev?)

I control backlight through /sys/class/backlight/acpi_video0/brightness with a script (via sudo) that provides a simple script to increment/decrement, set, retrieve and restore last backlight setting ...
0
votes
1answer
49 views

My C program CPU usage goes to 80% when redirecting to /dev/null

I wrote a C program that operates with UDP sockets and the serial port /dev/ttyS1 on uClinux. If I start the program normally as ./program the CPU usage is around 24%. However, if I start the program ...
0
votes
0answers
37 views

How to connect USB keyboard to BeagleBone Black in my own kernel and root file system?

I built uboot, linux kernel and root filesystem for beaglebone black. I have logitech k120 for business usb keyboard. In menuconfig of kernel i selected logitech keyboard driver, usb driver, usb ...
1
vote
1answer
1k views

How to determine which Berkeley DB version is used for RPM's database?

I am attempting to read and write the RPM database located in /var/lib/rpm under CentOS 5, and eventually other system types (CentOS 6, RHEL, etc.) The problem is that I don't know what version of ...
1
vote
1answer
1k views

libpcap missing

I’m trying to run a C program, but every time I try to run it I get this message: error while loading shared libraries: libpcap.so.0.8: cannot open shared object file: No such file or directory I've ...
2
votes
1answer
80 views

Solaris pstack how to read output / output format

I have the output from a Solaris pstack on a core file. I don't understand how to map the numbers in the log to the parameters that were being used by the functions in question at the time of the ...
2
votes
2answers
93 views

Why does strace show that syscall =?

I made a system call and recompiled the kernel, however upon running the system call it returned Killed. So, to trace it, I used strace, which shows the following message: syscall_0x224(0x7ffda7199738,...
0
votes
0answers
17 views

How to choose the C runtime library that will be included in the system image generated by Yocto?

As you all know, setting TCLIBC (eg. uclibc) in some distroX.conf will choose the C library with which the system is built (The compilation toolchain is going to build the system's packages with that ...
1
vote
0answers
24 views

Where is getrusage defined? [duplicate]

I've been looking into the getrusage function, which I see a prototype for within the file /include/linux/resource.h. I've tried to trace the directives to find where the actual function is, but I ...
3
votes
1answer
59 views

How to set ntpd server time without referencing another server?

I have an embedded system which synchronizes UTC locally using NTP. One of the clients in the system acts as time reference for the other clients. I guess you could think of it as stratum 0. A program ...
0
votes
1answer
2k views

Custom priority value: is a pthread high sched prio positive or negative?

I’m trying to reimplement in a backward-compatible way the RobotC API from C (although some details would better fit or would be easier with C++), and trying to reimplement their multithreading API in ...
0
votes
4answers
143 views

Deleting (some) comments from a C program

I need to use a bash script to delete full-line old-style comments from a C program, i.e., comments that begin (/*) and end (*/) on the same line, with no code on the same line.  This is an example of ...
0
votes
0answers
26 views

Solaris: internal compiler error: Failure while writing SunIR file?

Today our Solaris box started randomly failing to build our company software product. It's a fairly large build of hundreds of .c files. The error the Solaris C compiler cites: (On a random file in ...
-1
votes
1answer
163 views

OpenSSL Crypto development libraries are not installed properly in required location

When I configure turnserver-3.2.3.95 in my CentOS, I meet the following problem. $ cd turnserver-3.2.3.95/ $ sudo ./configure more is /bin/more install is /bin/install pkill is /bin/pkill Use TMP ...
0
votes
0answers
24 views

How does my application in Linux know how to find libraries in the common places [duplicate]

When I compile a simple C program for Linux, how does it automatically know where to find the standard C libraries when I run it? Take the simple Hello World program for example which uses printf to ...
0
votes
0answers
120 views

Cannot bind TCP/TLS listener socket to addr XX.XX.XX.XX:3478

After installing and configring turnserver on a CentOS-7.X server, I meet the following poblem. $ ./turnserver ... ... 0: Cannot bind TCP/TLS listener socket to addr 39.39.39.39:3478 0:...
5
votes
2answers
1k views

How to programmatically retrieve the GID of a running process

I need to write some C code to check the effective GID of a running process whose PID I know. I've not found any direct way to do this. There are a number of heavyweight kludges I could use, such as ...
4
votes
1answer
12k views

Changing a user's default shell

I have created a simple C shell on my local Linux server. I am trying to learn how to change the default shell of another user (bob) to be this new C shell that I have created. Is it possible to ...
2
votes
1answer
153 views

How is the C library able to access environment variables?

How do functions like getenv(3) access the environment when my program doesn't have any references to the environment?
0
votes
0answers
13 views

Howto unload and load or reload translation files using gettext and the libintl library

In the Minetest game project there is the claim that one cannot use gettext because of the lack of dynamically loading translations. My question would be howto unload or reload translation files ...
0
votes
1answer
20 views

Launch interactive app from script

I have an application built in C that uses fgets to read user commands from stdin. I want my embedded linux system to launch this application on startup, and put the user in the terminal of this ...
0
votes
0answers
15 views

Errors uploading files using an ftp client written in C using sockets

I wrote an ftp client in C using sockets, and a convenient API made by hubenchang0515 on GitHub called libftpclient. I followed the demo.c file shown in the repository; when I'm using the put command ...
4
votes
1answer
349 views

mmap: effect of other processes writing to a file previously mapped read-only

I am trying to understand what happens when a file, which has been mapped into memory by the mmap system call, is subsequently written to by other processes. I have mmaped memory with PROT_READ ...