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
14 views

Preprocess the Linux source code and save to another directory

Suppose I have the entire Linux source code in /tmp/linux-src. After menuconfig I want to do "some kind of gcc -E" where all the preprocessor macros other than #include are expanded so the actual ...
0
votes
0answers
22 views

Environment allowing Fortran to call a C function

I'm trying to install a large atmospheric model (WRF) on my newly set up Centos 7 machine. To start the installation process, the model's developers give a series of environmental tests. My set up ...
2
votes
0answers
50 views

virtual address translation in Linux

I try to translate a virtual address to a physical address. I can translate the below address. 00400000-00401000 r-xp 00000000 103:04 14292394 /home/user/readMaps 00600000-00601000 r--p 00000000 103:...
1
vote
0answers
17 views

Recover static library from executable

I have an existing executable for which a small amount of source code has been lost. In particular, the executable uses a few functions from a static library, and the source code for that library is ...
4
votes
0answers
82 views

Bring back a deleted file without copying its content [duplicate]

As long as there is an open file descriptor pointing to a file, I can bring it back with cp like this: # Open for reading exec 3< file # Delete rm file # Bring it back cp /proc/self/fd/3 file ...
-2
votes
0answers
49 views

I am trying to write a shell program to execute more than one command at a time [migrated]

My Code #include<stdio.h> #include <unistd.h> #include <stdlib.h> #include <sys/wait.h> int main() { char * arg_list[3]; arg_list[0] = "ls"; arg_list[1] = "-l"; arg_list[...
0
votes
1answer
34 views

How to install your signal processor SIGUSR1 and SIGUSR2?

By default, user signals SIGUSR1 and SIGUSR2 terminate the process or thread. How to make them set their handler? I tried to read various articles on this topic, but since I am new to this topic, it ...
0
votes
0answers
15 views

what did printf do in the shared memory [migrated]

#define _GNU_SOURCE #include <pthread.h> #include <stdio.h> #include <stdlib.h> #include <unistd.h> void func(); void main(int argc,char **argv) { printf("i am main\n"); ...
-4
votes
1answer
71 views

Why am I getting this [Broken pipe] error?

I'm on Ubuntu 18.04. I'm trying to do a buffer overflow attack. Here's the C program I wrote and am trying to attack: // test.c #include <stdio.h> void f(); int main(int argc, char *argv[]) {...
0
votes
0answers
42 views

How many memory segments?

I'm having trouble interpreting the output of a pmap command. I want to see how many memory segments are added to the process when one of the libraries (libupper/librot13) implementing a transform is ...
0
votes
0answers
21 views

Locating the system call table by means of the IDT and the syscall handler fails?

I'm working on an assignment for kernel programming classes and I need to locate the system_call_table memory address by means of the IDT and the system call handler. I've found numerous examples on ...
1
vote
1answer
31 views

Unused structure elements in regmatch_t array are not -1

The man page for regcomp and regexec indicates that, "Any unused structure elements will contain the value -1." Yet, in logic that checks the value of rm_so after my last match, that doesn't seem to ...
1
vote
2answers
45 views

Should programs remove temporary files in /tmp?

I have a program which uses temporary files, created using the mkstemps function. The files are created inside the /tmp directory. Does these files get removed automatically on program exit? I'm ...
0
votes
1answer
50 views

socket bind() errno 22 - no time-wait sockets

I am quite new to C & Linux and I tried to setup a TCP socket server for Data exchange with a C-Code I compiled and executed on a Ubuntu System. From a Tutorial I copied the following code (see ...
1
vote
2answers
120 views

Want to turn off “note” level messages in GCC

When I compile a C (no pluses) program using GCC, there are several levels of messages possible, like warning, error, and note. The note messages are useless and distracting. How do I make them go ...
3
votes
3answers
68 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
19 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
9 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
90 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
1answer
24 views

How does KDE Konsole handle a SIGTERM?

I have a particular setup: One manager program can launch and stop a program. One wrapper program which is composed of: Konsole. One program worker running into Konsole. My problem is: When ...
1
vote
1answer
41 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 ...
1
vote
1answer
148 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, ...
1
vote
1answer
77 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: Initially block all SIGINT signals using sigprocmask(). If sender send SIGUSR1 signal then unblock SIGINT for ...
0
votes
2answers
55 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
1answer
58 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 ...
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 ...
0
votes
0answers
16 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
37 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
66 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 ...
1
vote
0answers
26 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
61 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
0answers
49 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(...
1
vote
1answer
55 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 ...
0
votes
1answer
126 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
93 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
79 views

How to provide user access to /sys/class/backlight/acpi_video0/brightness programmatically (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
52 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
54 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 ...
2
votes
1answer
144 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 ...
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 ...
2
votes
2answers
108 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,...
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
61 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
0answers
29 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
2answers
73 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 ...
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
213 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:...
-1
votes
1answer
309 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
20 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
22 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 ...