Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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.

0
votes
0answers
26 views

C : what does “?” mean? [migrated]

1:snprintf( buf, sizeof(buf), 2: "%s exe=%s hostname=%s addr=%s terminal=%s res=%s", 3: message, exename, 4: hostname ? hostname : "?", 5: ...
-1
votes
1answer
30 views

can not read anything from serial port until i test something with “Screen” command

I think something wrong is in my setting (serial port, termios flag). when I run my code, it is waiting to receive data, but nothing happens, than I close my program and run screen command, it ...
0
votes
0answers
28 views

“Too many files” error, but no process exceeds maximum file limit [on hold]

I am trying to open a file in a C process of mine, but it fails, and I see a "Too many files" error. So I checked all of my processes for how many files they were using, and none of the processes in /...
-1
votes
0answers
22 views

How can I implement multiple kernels into bsd/Linux? [closed]

Like on the lowest level, on multiple cpu machines I want oop code organizing things in the fashion of multidimensional binary trees.
0
votes
1answer
44 views

Notify when file read [duplicate]

How can I register to event that let me know when specific file is read in linux? Can implement in c or in bash /shell script
0
votes
0answers
5 views

Why am I not getting my desired output? [migrated]

I tried running this program #include int main(){ int a=5; printf("%d %d", ++a,a++); return 0; } with gcc in arch-chroot on a armv7 device. I expect to get output 7 5 but ...
6
votes
1answer
374 views

Why doesn't mkfifo with a mode of 1755 grant read permissions and sticky bit to the user?

I'm creating a server and client situation where i want to create a pipe so they can communicate. I created the pipe in the server code with mkfifo("fifo",1755);: 1 for only user that created and ...
0
votes
0answers
32 views

How shell delivers user's input to program and shows program's output? [duplicate]

Since shell (for example, Bash) is just another program with its own stdin/stdout/stderr streams, how does it deliver user's input to running program? Here's simple program, that reads value from ...
1
vote
0answers
44 views

Network interface with unknown speed

When I try to print the maximal throughput of my network interface, I receive an error: $ cat /sys/class/net/<interface>/speed cat: /sys/class/net/<interface>/speed: Invalid argument ...
1
vote
0answers
34 views

Where to look for data type definitions?

Is there any reference material like man pages that informs on C datatypes? I thought this would give me something, but not: $ man size_t No manual entry for size_t $ man -k size_t size_t: nothing ...
-1
votes
1answer
40 views

Byte swap question (Bitwise operation) [closed]

I have seen some bitwise operation practice questions (in C language) and there was one I didn't understand: you had to swap the nth and the mth byte in a specifc integer "x" using only bitwise ...
0
votes
0answers
21 views

How to make C library installable with angle brackets as <mylib.h> on Mac [migrated]

If I go into /usr/local/lib, I see a bunch of folders and .dylib files, the dynamically linked library files I'm pretty sure. If I go to /usr/local/include it has a bunch of .h files each of which has ...
1
vote
0answers
28 views

Own boot parameter in Linux kernel gives no outprint (Homework)

The task is to write a own boot parameter in the linux kernel that activates printk under the kernel initiation. The Linux kernel version that is edited is 4.16.7 (buildroot 2018.11.2) and my ...
0
votes
0answers
5 views

How to link a C library to an Assembly library on Mac with clang [migrated]

I have this in my C library: myc: @clang -I . -dynamiclib \ -undefined dynamic_lookup \ -o myc.dylib myc.c .PHONY: myc And this in my assembly library: buildasm: @nasm -f ...
1
vote
1answer
28 views

something wrong with my makefile about wildcard

I have a bunch of .c test source file in directory tests/. Now I want to compile and link them respectively and output the executable *.out in tests/. So I wrote a makefile, which didn't work. # ... ...
0
votes
1answer
51 views

Where does main function get allocated?

When concerned with a memory layout for a process, all function calls within the process get a new stack-frame into the stack. I'm not sure if this is true for main function as it seems like main ...
0
votes
2answers
55 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
35 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
37 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
57 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
21 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
72 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
35 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
94 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
59 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
51 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
419 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
63 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
1k 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
44 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
51 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
63 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 ...
3
votes
1answer
128 views

How is the C library able to access environment variables?

This may be a dumb question, as I feel like I must be overlooking something fairly obvious, but how do functions like getenv(3) access the environment when my program doesn't have any references to ...
4
votes
3answers
423 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
45 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
55 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
46 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
32 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
66 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
67 views

How to grep using gcc to find definitions in standard librarys [closed]

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 know #include <stdint.h> #include <string.h> #...
-1
votes
2answers
70 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
25 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
777 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
0answers
83 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
81 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
53 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
38 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 ...