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
1answer
100 views

What codes are copied to the child process?

If we call the method fork() inside an if statement, does the generated child process enter into the else statement ? #include <stdio.h> #include <unistd.h> #include <stdlib.h> #...
1
vote
2answers
1k views

File Operations and Processes

Is it possible that two different processes(parent and child) can see the same text file and manipulate it ? I accomplished this, but I had to open the file in both processes by using fopen(). My ...
1
vote
1answer
170 views

Process and fork() Method

I am new to Operating Systems and Linux hence this may be very basic question but I cannot find an answer. According the resources I have read so far, the fork() method creates new process by ...
1
vote
1answer
1k views

Creating a specific process tree and terminating it

I am currently taking a Computer Systems class and am having trouble with a homework problem. I have to create this specific process tree: I also need it to stay in this state for a while (using ...
2
votes
1answer
267 views

Compile ptrace() program on OSX

I have this simple C program on MacOS: #include <stdlib.h> #include <sys/wait.h> #include <stdio.h> #include <sys/ptrace.h> int main(int argc, char *argv[]) { pid_t pid = ...
2
votes
1answer
528 views

Is there a C API to get a SELinux file context?

Is there a way in C to get the SELinux context of a file?
3
votes
2answers
831 views

Why is cpu_idle called as the last function of the start_kernel routine?

I'm reading the start_kernel function in /init/main.c. The last function called in start_kernel is rest_init, and at the end of rest_init, cpu_idle is called. Why is it called as the last function ...
-5
votes
1answer
1k views

*** glibc detected *** /filepath/ : double free or corruption (!prev): 0x00000000007bed40 ***

I need to understand the below C error, *** glibc detected *** /path/readnbn: double free or corruption (!prev): 0x00000000007bed40 *** ======= Backtrace: ========= /lib64/libc.so.6(+0x76508)[...
0
votes
1answer
112 views

How to make it so that parent creates child, exits before the child completes, then the orphan is re-parented by init?

#include <stdlib.h> #include <stdio.h> #include <sys/types.h> #include <unistd.h> #include <sys/wait.h> int main () { pid_t child_pid; child_pid = fork (); // ...
2
votes
1answer
18k views

gcc /usr/bin/ld: cannot find -lglut32, -lopengl32, -lglu32, -lfreegut, but these are installed

I'm trying to compile a demo project, what is using OpenGL. I'm getting this error message: But I have everything: What is happening? If I have all of the dependencies, why does it not compile? I ...
3
votes
2answers
3k views

Get hex-only output from objdump

Say for example I've got this C function: void f(int *x, int *y) { (*x) = (*x) * (*y); } When saved to f.c, compiling with gcc -c f.c produces f.o. objdump -d f.o gives this: f.o: file ...
0
votes
0answers
316 views

Object library not found by shared object library

I'm trying to build a shared object library but when I produce the shared object library it says the object file is not found. OSError: lib1.o: cannot open shared object file: No such file or ...
2
votes
1answer
44 views

File doesn't seem to be regular but is listed as such

From what I understand, on Linux/UNIX files from which you get system info aren't regular files but rather device files and yet I have encountered a file that doesn't seem to be regular (due to its ...
0
votes
1answer
100 views

How to detect and get the real size of device files?

The C fsize function returns 4096 for special/device files, but is there an integrated function to know the real size of a device file if it is finite ? I would also like to know if there is a way to ...
0
votes
1answer
546 views

Using a loop to generate command line arguments

I am attempting to use a for loop to run command line arguments, I have never attempted this and I am having some trouble. I am using the following commands: for((a=1; a<20; a++)); do ./a....
3
votes
3answers
3k views

Behaviour of the backspace on terminal

This is about the behaviour of the backspace (\b) character.  I have the following C program: int main() { printf("Hello\b\b"); sleep(5); printf("h\n"); return 0; } The output on my ...
1
vote
2answers
2k views

Read /proc/pid/maps using read()

I want to extract the information from /proc/pid/maps, such as: the start address, the end address, and the permission. However, for learning purpose, I want to use the low-level system call, such as:...
3
votes
1answer
646 views

Limit and measure VSS/RSS

I'm writing a program on Ubuntu 16.04, and it will fork, do some setups and exec another program. I need to: Limit the maximum VSS the program could use Limit the maximum RSS the program could use ...
1
vote
2answers
678 views

When is the heap used for dynamic memory allocation?

Every post about memory allocation seems to either explain how mmap is used or how sbrk was used, without regard for how these can be contextualized with the heap. I have gathered that the heap plays ...
-1
votes
1answer
1k views

What does exactly does GNU make dep do?

I am trying to understand GNU Make and trying to understand some c code and GNU autotools. There's a folder let's say lib, with three subfolders and a makefile. lib ...libA ...---compile.sh ...---...
7
votes
3answers
1k views

C system(“bash”) ignores stdin

I have a file input: $ cat input 1echo 12345 and I have the following program 1st version #include <stdio.h> #include <stdlib.h> int main() { system("/bin/bash -i"); return 0; } ...
1
vote
1answer
229 views

OpenCV based programs optimization embedded linux OS [closed]

I'm building my own Embedded Linux OS for Raspberry PI3 using Buildroot. This OS will be used to handle several applications, one of them performs objects detection based on OpenCV (v3.3.0). I ...
1
vote
2answers
410 views

force output to input (buffer) like “\033[6n” in a script

I have tried using pipes and redirections to have (C program or scripts) output end up on the input buffer, the way printf "\033[6n" does, but no positive results. Does anyone know how this is ...
0
votes
1answer
167 views

astyle does not change source file formatting

Why isn't the astyle program formatting my c source file? Background: I copy-and-pasted a c source file from gitlab and for some reason, the resulting file was jumbled. I was hoping to be able to run ...
1
vote
1answer
68 views

What libraries/files are needed for ncurses refresh() under a chroot environment in Ubuntu 16.04

I tracked down my issue to the following point. If I run my app by itself it works fine. However if I chroot it, it seems to work fine until the current game ends and then it core dumps calling the ...
4
votes
0answers
705 views

Portable way to get all thread ids running inside a process.

During the porting of an application form Linux to FreeBSD I came up with the following problem. I need to get all thread id of all threads running inside my application. In terms of PThreads, I need ...
0
votes
1answer
585 views

Do we need c libraries when running a program?

The executable file should be in machine code. So, will make system calls without a need for c libraries. But, I can not figure out what this image means? Is it just an abstraction method?
3
votes
0answers
540 views

Hooking sys_execve on Linux kernel 4.6 or higher

Kernels lower than 4.6 use assembly stubs to harden the hooking of critical system calls like fork, clone, exec etc. Particularly speaking for execve, the following snippet from Kernel-4.5 shows entry ...
3
votes
0answers
464 views

PortAudio appears to be broken on Debian/VirtualBox

I'm running Debian 9.2.1 in VirtualBox 5.1.30 on a Windows 7 host. I'd like to use the PortAudio library in a project so it can be used on multiple platforms, but I can't get it to behave even with ...
5
votes
2answers
1k views

How to redirect error info of executable C program to stdout? (MAC OS X)

I want to write a automatic C program checker. For example, I have a toy "hello.c" program: #include <stdio.h> int main() { int a, b; while (scanf("%d %d", (&a)-1000000000000000, ...
2
votes
1answer
478 views

How do I compile my C program within Vim, but not to the current directory?

So the command I've been using in Vim for a while is: map <F10> :w<CR> :!clear; make %<<CR> :!./%<<CR> Which takes the current name of the file, compiles and then runs ...
0
votes
1answer
335 views

Why is sigset_t in glibc/musl 128 bytes large on 64-bit Linux?

Why is sigset_t on 64-bit Linux 128 bytes large in glibc and musl? #include <signal.h> #include <stdio.h> int main() { printf("%zu\n", sizeof(sigset_t)); //prints 128 with both glibc ...
0
votes
1answer
164 views

Follow files execution by a kernel module [closed]

I'm currently doing some project of secure the kernel with syscall hooking and logs... Now I've done hooking read, and socket system calls, and when I tried to do the same thing with execve (to follow ...
-2
votes
1answer
28 views

Regarding declaring array in c [closed]

Whenever I create an array in C using sublime text editor I get following error The code written is:
1
vote
0answers
35 views

Is there a standard/accepted way for a plugin library to identify its location on disk?

I am working on a C program that has a plugin architecture. We build and package both .rpm and .deb packages. Some plugins have additional non-binary resources, such as image files, or script files ...
0
votes
1answer
101 views

what are the cflags of this microarchitecture?

I'm looking the cflags for the turion X2 M500 processor I'm doing grep -m1 -A3 "vendor_id" /proc/cpuinfo and the output is: vendor_id : AuthenticAMD cpu family : 16 model : 6 model name ...
2
votes
1answer
918 views

What is the NR_Syscalls value?

I am trying to understand code for a C program that among other things, increments the NR_syscalls value of the Linux kernel. Does the NR_syscalls value store the number of system calls in the system ...
2
votes
0answers
704 views

Unhide the hidden module in linux kernel

I coded a LKM which has a functionality of hiding itself from procfs and sysfs. The problem is when I try to unhide it I get the following error :libkmod: ERROR ../libkmod/libkmod-module.c:1882 ...
0
votes
1answer
52 views

Error while trying to automate mutt using C

I am trying to automate mutt in C. To send a mail with attachment in mutt one can use: echo "what_you_want_to_print_in_body" | mutt -s "Subject" -a "file_path" -- recipient@domain.com but when I ...
1
vote
0answers
204 views

Does SO_ATTACH_FILTER reset the socket's receive buffer?

If a filter is already set and there are unprocessed packets in the sockets receive buffer will calling SO_ATTACH_FILTER to set a new updated filter flush the buffer, i.e is it the same as BSD's ...
0
votes
2answers
406 views

What was the reason for lseek function to return file descriptors as long integer? [closed]

According to the book Advanced Programming in the Unix Environment :- "The character l in the name lseek means ‘‘long integer.’’ Before the introduction of the off_t data type, the offset argument ...
0
votes
1answer
40 views

Interpreting `man` C library name

Certain C library files show multiple #include files at the top. For instance, man connect shows SYNOPSIS #include <sys/types.h> #include <sys/socket.h> However, in order to call ...
2
votes
1answer
75 views

How do I merge two C header files, such that re- #defines are removed?

Supposing I have: sdk.h: #define foo 1 #define bar 1 app.h: #define foo 0 How can I generate a merged.h that looks like this, given I want app.h to redefine anything already defined in sdk.h: #...
2
votes
2answers
1k views

Tool to print out functions being called during run time?

I am looking for such kind of a tool on either Unix/Linux platform which can achieve: I have the source files and I compiled the application myself (the source code is in C, although I don't really ...
1
vote
4answers
4k views

Is it possible to write to other file descriptors in C?

If I wish to redirect all stdout to a file, I would run my_prog 1> out If I wish to do the same for stderr, I would run my_prog 2> err However, I know that in shell there are other file ...
0
votes
2answers
251 views

Is `open()`, `mmap()`, or neither, the more fundamental function?

In the Linux kernel, is open(), mmap() or neither, the more fundamental way to access a file? By "fundamental", I mean "does either ultimately call the other or a simple helper function of the other?"....
1
vote
1answer
222 views

Operate on BlueZ provided file descriptor in C

I am attempting to work with the org.bluez.Profile1 in BlueZ 5.44. When connecting with a new device via the NewConnection DBus method, we get a file descriptor to work with. I am fairly confused on ...
1
vote
2answers
744 views

select(2) on FIFO on macOS

On Linux the included program returns from select and exits: $ gcc -Wall -Wextra select_test.c -o select_test $ ./select_test reading from read end closing write end first read returned 0 second read ...
1
vote
1answer
296 views

Should I downgrade gcc for legacy code?

I inherited a legacy system that looks like this. $ uname -a Linux pos-sthlm-globe-as-209 2.4.19-dxx #10 Thu Dec 22 15:47:12 CET 2005 i686 GNU/Linux niklros@pos-sthlm-globe-as-209:~$ gcc --version 2....
1
vote
2answers
746 views

How to allow backspaces in unbuffered/non-canonical mode?

I'm working on multiple C programs like a shell and a text editor that require to be run without the ECHO and ICANON flags. I disabled these using termios.h and managed to write my own gets function ...