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
2
votes
0answers
59 views

non-root access to physical blocks occupied by a file

ioctl() and FIBMAP can be used to determine the physical blocks occupied by a file, given logical blocks obtainable via stat(); however, root access is required. Why is root access necessary for ...
1
vote
0answers
301 views

Reserve memory in RAM and in the desired physical position

I'm trying reserved 2GB in RAM, but i like reserved in the start memory, in the 0x00000000 position to 0x80000000, Can I do it? I read in the LDD3 that you can reserver spaces in the memory, but in ...
1
vote
2answers
88 views

nano text file formatter? [closed]

Is there a SIMPLE way to format nano file text? My code is getting pretty messy, so it MAY help to format it.
5
votes
2answers
518 views

Avoid command injection with system() api [closed]

We have a legacy C code used to allow less privileged user to run custom scripts with escalated privilege. This has SUID bit set. This code restricts the PATH env to a specific folder and then uses ...
0
votes
1answer
28 views

How to get Mac OS to remember previous auth. from my executable file

I'm writing a tiny unix executable file that changes my macbook's system time manually. Of course, this requires a password, and so I used the system() function to interface with the terminal and ...
0
votes
2answers
30 views

Ubuntu, using a shell script to loop a C program

I have a C program ./myProgram 1 (where 1 is the argument fixed) in the directory gianni@mylinux:~/myWork/myApplication$ ./myProgram I wish to run this C program 100 times using a loop insted a ...
1
vote
1answer
27 views

Should I free the fstab pointer returned by getfsent?

#include <fstab.h> struct fstab *getfsent(void); http://man7.org/linux/man-pages/man3/getfsent.3.html getfsent reads a line from /etc/fstab file and return a variable of type struct fstab*. ...
2
votes
2answers
141 views

Test question regarding grep

Below is a the test question for a practice LPIC-1 exam I took. The correct answer is A. I'm really dazzled at how this is the case. If it's not too much trouble can someone walk me through how A ...
1
vote
1answer
159 views

How to check the signal handler in Linux

I have read this discussion which discuss about how to check the signal actions of each process: How can I check what signals a process is listening to? However, I want to use C/C++, Python or other ...
2
votes
0answers
275 views

Time measurment in Linux kernel: how are clock_gettime, gettimeofday and getrusage related?

I am trying to understand how time is measured by the Linux kernel. I tried to go through the kernel code, but I miss the big picture to understand the code that I'm reading, even if this article ...
1
vote
1answer
80 views

Processor not seeing changes to POSIX shared memory?

Context: I am using POSIX shared memory to provide a set of processes with a shared memory space. I have used this scheme for some time now in order to share data, and it's working okay. However, I ...
1
vote
1answer
399 views

replacing current shell with execl()

In the following C program: #include <stdio.h> #include <unistd.h> #include <stdlib.h> int main(void){ char *shell = getenv("SHELL"); execl(shell, NULL, NULL); ...
0
votes
1answer
90 views

Finding a man page with a standard C or POSIX type? [duplicate]

Is there a way to find a man page given a Standard-C-type or POSIX-type? Such as man size_t or man uintptr_t. This kind of thing can get confusing because uintptr_t is defined in stdint.h, and size_t ...
-1
votes
1answer
254 views

What Debian/Ubuntu package has the documentation for the standard C headers?

On the back of this question, but Debian/Ubuntu specific that has C-standard library headers like (taken from Wikipedia) assert.h , complex.h , ctype.h , errno.h , fenv.h , float.h , inttypes.h , ...
1
vote
0answers
54 views

Fakeroot on macOS tries to delete system directories

I’m having a problem with fakeroot on macOS. I created a pacman fork. When I’d like to delete a package, pacman tries to delete /usr/ instead of a subdirectory. On Linux, it is working fine, though. ...
-1
votes
1answer
1k views

What does the -O2 option for gcc do? [closed]

What does the -O2 option for gcc do? eg. gcc -O2 file1.c -o file1.o
0
votes
0answers
61 views

Is there C language documentation on Linux? [duplicate]

Is there a package on Debian or some other Linux media that provides documentation for the C language? I mean in particular man pages. Eg. so that I can check docs for typedef or other basics (and ...
1
vote
2answers
449 views

Redirecting a string to current TTY

I have some code: char *tty_name = ttyname(STDIN_FILENO); char command[255] = "/usr/sbin/writevt -t "; strcpy(stpcpy(command + 21, tty_name), " -T ' \r'"); system(command); It writes a "space" and a ...
1
vote
1answer
108 views

behavior of interrupt signal after forking

I used the following code while studying signals. #include<stdio.h> #include<sys/stat.h> #include<sys/wait.h> #include<unistd.h> #include<stdlib.h> #include<signal.h&...
0
votes
1answer
204 views

Does a forked process copy all mapped memory when writing?

I understand that a forked process maps the parent's memory and copies it when writing to it. Does it copy just what it needs written or does it copy the entire mapped memory ?
1
vote
1answer
103 views

Can I write a console program that works with multiple character encodings? [duplicate]

I am writing a console program in C. I expect the Terminal that my program is running in to have its character encoding set to UTF-8. This means that I am sending UTF-8 encoded strings to the ...
-1
votes
1answer
21 views

How can i send for 1 minute via a pipe, random numbers of 2 or 3 figures from the parent process to the child one?

Additionally to this task I have to count in the child process all the numbers received from the parent process and print them! Thanks in advance! :)
50
votes
4answers
11k views

Why does a program with fork() sometimes print its output multiple times?

In Program 1 Hello world gets printed just once, but when I remove \n and run it (Program 2), the output gets printed 8 times. Can someone please explain me the significance of \n here and how it ...
0
votes
0answers
73 views

system call to peek next byte from serial port

have a program that does an open() on /dev/ttyACM0. I know how to get bytes available using ioctl(), but I want to know what is the next available byte's value, without grabbing it. (A peek). Is by ...
2
votes
1answer
332 views

How to print filled shapes in the terminal?

How to print a filled circle or shapes in the terminal like:
2
votes
0answers
97 views

Portable serialization of data in the Linux kernel

Is there really no functions / macros in the Linux kernel for portable serialization of integers (and other data types) to byte arrays? I would think that this must be such a common use case. For ...
0
votes
1answer
1k views

Playing with network interfaces in C/C++ [closed]

I've been looking for a way to manipulate network configurations. Required functions are; Set/get ip/netmask of an interface. Set/get route table information. Add/remove networks from/to route table. ...
0
votes
1answer
217 views

How to continuously check ltrace command output in C program [closed]

I'm trying to capture output of ltrace command using C program. I have tried using popen() but that's not working, I need to capture continuously output not only once. Below is my code: #include &...
-2
votes
1answer
68 views

How to schedule a C program to execute at a certain time then email output?

How would one go about scheduling a C program to execute at a certain time, then email the output to someone upon completion? I'm personally working in ubuntu, but even a general answer would be great ...
1
vote
1answer
66 views

gsl.pc not found on Fedora 27

I installed gsl on my Fedora 27 machine with: sudo dnf install gsl When I re-run this command, I get the output: Package gsl-2.4-3.fc27.x86_64 is already installed, skipping. But when I run: find ...
0
votes
2answers
853 views

is there any C library equivalent of killall in Linux?

I want to kill other application similar to killall command as I know application but can not get PID at run time. This has to be done in C code. I know kill() but it need PID. Any other way ...
2
votes
1answer
414 views

Why is LDBL_MAX 1.18973E+4932 and how is this possible?

If I write a C program to say the value of LDBL_MAX the largest value for a long double, #include <float.h> #include <stdio.h> int main(void) { const long double max = LDBL_MAX; ...
4
votes
2answers
1k views

Does POSIX standardize the file descriptor numbers?

Does POSIX mandate that stdin is 0, stdout is 1 and stderr is 2 or is this only a convention? Do other systems diverge from that convention or is it a safe assumption?
3
votes
1answer
2k views

Problems caused by STDIN set to non-blocking mode

Certain commands start to consistently fail in a given terminal window: $ sudo apt-get install ipython ... After this operation, 3,826 kB of additional disk space will be used. Do you want to ...
2
votes
1answer
2k views

why i can get root after running system(“/bin/sh”) in c file?

I am currently logged in as seed and after running test.c, on my Ubuntu system, I get root permission. I am just wondering why system("/bin/sh") can make a such change? Firstly, I su root and compile ...
0
votes
1answer
335 views

Why protocol type value for IP protocol in ethernet frame is 8?

I am writing a simple packet processing program. Here is code excerpt: void print_ethernet_header(unsigned char* buffer) { struct ethhdr *eth = (struct ethhdr *)buffer; fprintf(...
0
votes
1answer
383 views

Send SIGTERM to a suspended process

I have 2 processes written in c, I'll call them 'parent' and 'child'. Parent creates child and child enters a loop where it does some code, then raises SIGSTOP. If a certain condition is reached, the ...
0
votes
0answers
30 views

Millisec. in filename with C

I find no indication that there is a format for milliseconds in C. I save images more than once a second and need an additional index. My code now is: time_t now; struct tm ts; time(&now); ...
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
1answer
2k views

Script to find functions in a C program [closed]

I am trying to find solution to this following problem: Given the directory structure: project/ bridge/ mysql_bridge.c postgres_bridge.c My code should retrieve all functions in .c files ...
0
votes
2answers
70 views

iptables from execve c function not accepting flags

When I run $ /usr/sbin/iptables -I INPUT -p tcp --dport 80 -j ACCEPT from the command line it works fine. However when I compile and run this code #include <unistd.h> int main() { char *...
1
vote
2answers
83 views

Why opening file for binary access is “meaningless” on Unix, nor the “+” for both read/write?

I am reading The C Programming Language (2nd Edition). On page 157 and 158 the author gives a code snippet of fopen in the Unix system. At the end of the snippet the author added: In particular, ...
0
votes
1answer
95 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
160 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
254 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 = ...
1
vote
1answer
493 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
770 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)[...