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

Is there any way to know how many sockets have been created by a C program?

I have been running a C program which connects to a Redis database every once in a while. After running the program for a few hours it was displaying "Cannot create socket: too many files open". I'm ...
0
votes
1answer
41 views

Why does make regenerate the main executable file in this makefile?

I have the following makefile: ############################################################################################################################################ ############################...
-1
votes
1answer
49 views

Do we need to open a file to get its attributes?

int stat(const char *filename, struct stat *buf); int fstat(int fd, struct stat *buf); Do we need to open a file to get its attributes? To access the attributes of a file, do we need to access the ...
2
votes
1answer
37 views

Purpose of _LINUX_EXPORT_H macro

What is the purpose of defining _LINUX_EXPORT_H in include/linux/export.h? It seems to be defined in this file and never referenced anywhere else. Is it redundant? Link: _LINUX_EXPORT_H in torvalds/...
1
vote
1answer
76 views

MacOS's counterpart to Linux's unshare(2)

Does MacOS have a counterpart to Linux's unshare(2)? I'd like for the following to fail on both systems. #define _GNU_SOURCE #include <stdlib.h> #include <sched.h> int main() { #if ...
1
vote
1answer
178 views

Optimal sharing of a ring buffer between processes

We're implementing an embedded Linux system and have to provide a live updating graph on a website that shows data coming from a background process in the system. The question is how to optimally ...
0
votes
0answers
31 views

How to empty the list of supplementary group IDs for a process?

When I create a child process, it inherits the supplementary gids of the parent. If the parent is a root, then the child has (0) as supplementary gid. This behavior is not desired. Is it possible to ...
2
votes
1answer
139 views

Prevent Bash from removing zero-bytes in double-quoted string?

I need to supply arbitrary bytes for an argv argument of a C program. However, if the bytes are put within double-quotes, the zero-bytes are removed as can be seen below: v="$(python -c 'import sys;...
1
vote
1answer
56 views

CPU statistics calculation algorithm

I too many search on internet to found algorithm calculated %Us , %Sy , %Id , ... on result of top command . but can not found any documentation . some documents like this or this calculate cpu ...
1
vote
1answer
123 views

Shell crash and how to debug it

As part of my C application running on Linux, I call a script using the system( ) library function. This script does a umount of a connected USB flash drive. Very rarely (1 in 7-8k) iterations, I see ...
0
votes
2answers
67 views

Trying to do a Proof of Concept of poisoning 'ls' binary to hide files and folders

I am currently trying to modify 'ls.c' source file in order to hide files and folders containing the word hidden. After doing some research, I've found that this could be possible by adding this code ...
0
votes
1answer
169 views

Read arbitrary amount of memory with process_vm_readv

For process_vm_readv the linux man page states: [...] (Avoid) spanning memory pages (typically 4KiB) in a single remote iovec element. (Instead, split the remote read into two remote_iov elements ...
3
votes
1answer
660 views

Determine free space available on a USB flash drive in C (linux)

I would like to figure out the available free space on a USB flash drive in a C program in Linux. I have earlier used system("df -h /dev/sda1") to figure it out but using system command in a Linux C ...
2
votes
1answer
143 views

Kernel can't find initrd?

When trying to mount ext2 I get this error: Creating 4 MTD partitions on "MPC8313RDB Flash Map Info": 0x000000000000-0x000000100000 : "U-Boot" 0x000000100000-0x000000300000 : "Kernel" 0x000000300000-...
9
votes
1answer
2k views

How different is compiling source code in Debian GNU/Hurd from Debian GNU/Linux?

I was trying to compile libnetfilter_conntrack source from github as it was requested by iptables while compiling iptables and as any of these were not available in the HURD software repo and ended up ...
0
votes
0answers
113 views

How to programmatically get a hostname's IP address on a local network in C?

I'm working on a project where I'd like to transfer data over TCP/IP sockets in a C program between two computers connected over WiFi to a home router, both are running Debian-based Linix ...
0
votes
2answers
59 views

Text from standard input not visible after program exits from a readline

I am facing an issue where the text from my stdin is not visible from on my terminal. My program does the following Sets a SIGALRM handler which exits a program when there is no input from the user ...
1
vote
1answer
240 views

Detect if USB disk is mounted in C application in Linux

I would like to check if USB disk is mounted in a C application. I know that in a script I can accomplish this via mount | grep /mnt (the mount point where udev mounts the USB drive) but I need to do ...
2
votes
1answer
148 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?
5
votes
3answers
1k views

Passing generated empty strings as command line arguments

I do the following: $ ./input "" Output: argc 2 argv[1][0] 0 But if I want to pass (several) empty quotes in program based manner: $ python -c 'print "\"\""' "" ./input $(python -c 'print "\"\""'...
5
votes
1answer
57 views

%c formatted string shows different behaviour in the shell and in C

If i write a very simple line of code in C: printf("Ascii char for %d is %c\n",65,65); It simply prints A, as ascii value of 65 corresponds to character A. But if I use the same code in shell and ...
1
vote
0answers
17 views

Can I limit a process's access to specified files and stdout only without root?

I want to setup a server for students to upload C code. The server compiles C code, run the binary and shows output to students. Now I am having security concern. Students can upload any code, but I ...
1
vote
0answers
84 views

seteuid fails even when all UIDs are 0

I have some C++ code on a Linux machine whose purpose is to run some code as an arbitrary user. #include <sys/capability.h> #include <unistd.h> void doAsUser(uid_t uid) { if (...
2
votes
1answer
65 views

Why does GNU Indent collapse one level of indentation?

When I try to format my C code using GNU Indent, it doesn't seem to deal with multiple levels of nested indentation. Specifically, it seems to collapse the second level of indentation. For example, ...
-2
votes
1answer
40 views

How to write a script to kill & clean the resources of executing process?

I have an application running in c language (my_process.c) and a script (stop_process.sh) to stop the application and clean up all resources held by the process. In the application code, let's say I ...
0
votes
1answer
77 views

Still safe to use distro after applying c program to it?

I installed elementary OS Juno on an old iMac 5,1. The Computer uses a 32bit EFI, which is not able to boot elementary OS Juno so I decided to follow Matt Gadients guide for a little workaround. You ...
0
votes
1answer
120 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
votes
2answers
72 views

Child processes seem to run code from before they were created. How do I stop it?

I'm trying to write a program that has a single parent process create multiple children in a while loop. For testing I started trying to make only 4 processes (1 parent and its 3 children). But it ...
0
votes
1answer
57 views

Stopped process reasons?

I'm running a program using a batch file and it keep giving me this ERROR: STOPPED PROCESS I've noticed that the program stops each time in a place a little after the place he stopped the last ...
7
votes
5answers
1k views

Executing a bash script or a c binary on a file system with noexec option

Can anyone explain in details what is going on with the following. Let's imagine I am mounting a directory with noexec option as follows: mount -o noexec /dev/mapper/fedora-data /data So to verify ...
0
votes
1answer
267 views

How to supply a command to 'stdin' of a running process from a second shell?

If you have a process that is waiting for user-input from the stdin scope, then how can you supply that user-input from a second terminal ? Specifically, if I run the c-program while(1){ fgets(...
0
votes
1answer
241 views

Linux kernel module development buildroot

I have build a linux kernel for the beaglebone black using buildroot. Now I would like to develop a hello world linux kernel module application: #include <linux/init.h> #include <linux/...
0
votes
1answer
82 views

Can we execute the pro-c file which is compiled on UNIX on Debian 9? [closed]

I have a pro-c file which is compiled on UNIX. The script logins to oracle DB and interacts with DB and update some values there in some tables. We are migrating from UNIX to Openshift Container ...
0
votes
1answer
53 views

What is the IP address of my local interface that is required by IP_ADD_MEMBERSHIP?

In this man page http://man7.org/linux/man-pages/man7/ip.7.html, it is written that IP_ADD_MEMBERSHIP can be used to join a multicast group. We need to provide, as input, in particular, the IP ...
1
vote
1answer
168 views

DWM Unicode Support

I'm in the process of creating a nice looking statusbar with DWM and I want to implement unicode symbols with font awesome. Supposedly I can use the Pango patch but its out of date (for version 6.1) ...
2
votes
0answers
62 views

No such process (3) when not connected to a network (AF_ROUTE)

When I am connected to a network, I can send a struct rt_msghdr* to the kernel and receive a corresponding route. However, when I disconnect from the network and try to send the same route message ...
0
votes
0answers
73 views

Turning USB into a terminal

I have a hardware device that connects via USB without creating a specific /dev/something. It does change the time on /dev/ptmx and /dev/char but that's about it. All I know are the VID:PID of the ...
0
votes
1answer
47 views

How to avoid multiple 'libFoo.so' open() calls at application launch? [closed]

I have the next so file in /UNI/System/Libs/libmbedcrypto.so.3 directory. When I launch my application, that use libmbedcrypto.so.3 with strace I see: open("/UNI/System/Libs/tls/v7l/neon/vfp/...
1
vote
3answers
96 views

Strange zombie process responds to signals?

I have a strange situation. I have a c-written program “A” which takes as argument the name of other executables, e.g. “B”, “C”, “D” etc.. The main job of “A” is to fork and start “B”, “C” etc, then ...
0
votes
0answers
203 views

Retrieving the SO_INCOMING_CPU of a UDP Socket?

The socket API provides an SO_INCOMING_CPU option, the details of which are provided in the man page: SO_INCOMING_CPU (gettable since Linux 3.19, settable since Linux 4.4) Sets or gets ...
3
votes
1answer
182 views

Does Bash imitate Locale-Specific Translation from C?

Bash manual mentions that 3.1.2.5 Locale-Specific Translation A double-quoted string preceded by a dollar sign (‘$’) will cause the string to be translated according to the current locale. ...
5
votes
1answer
700 views

Why are there multiple copies of header files in /usr/include?

I've been browsing my /usr/include folder trying to get acquainted with the layout and I've noticed that there are multiple copies of header files (at least by name, I didn't actually diff them to see ...
1
vote
1answer
47 views

file lock existence check on remote host

I want to check the existence of file lock on a file in gluster file system. So that I can see from any host that whether file lock is held by any process (remote or local) on file in gluster file ...
0
votes
1answer
890 views

Is it safe to send SIGUSR1 to a program, and why? [closed]

When you send SIGUSR1 signal (say the signal handler has been set in advance) to a program while it is executing sleep(100), the signal is caught correctly but sleep(100) is terminated just after the ...
0
votes
1answer
88 views

GCC Compiler Error Again

I was once again trying to install a compiler onto my SGI Indy computer running Irix version 6.5, and this time, I found a file that has all of the libraries I thought I would have needed. When I ...
1
vote
1answer
1k views

Building shared library which is executable and linkable using Cmake

How to create an executable shared-library using cmake? Something like: libtest.so :: linkable shared library libtest.so :: executable too Note: gcc/g++ options are known to achieve the ...
1
vote
1answer
718 views

Emulating a character device from userspace

We are currently working on building a system for data visualisation for different sensors. To make development of the Linux application possible we would need to emulate the behaviour of the ...
0
votes
1answer
567 views

How to pass argv arguments to a C program using a file or python script in linux?

I used to be able to pass input to C program by first writing a python script and using pipe to send it to the C program as an input or write the output of python script to a file and just doing r &...
1
vote
0answers
135 views

Compiling module on OpenWRT: make can't find build directory

My setup: OpenWRT 18.06.1 Raspberry Pi 2 B Kernel 4.9.120 Attempting to build a very simple hello world kernel module results in the following error: # make make -C /lib/modules/4.9.120/build M=/...
0
votes
1answer
503 views

Which Libraries can be called inside a Kernel Module

Looking for a list of libraries which can be called from a custom Kernel Module. I understand that there are restrictions compared to user space and libraries like <stdio.h> and <string.h>...