The Stack Overflow podcast is back! Listen to an interview with our new CEO.

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
1
vote
2answers
747 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 ...
2
votes
0answers
72 views

Time between process runs is occasionally too long, how can I set a maximum time? [closed]

I am using a raspberry pi to grab data through a SPI port. Attached to the SPI port is a PIC, programmed so that it samples on an A/D at 12.8kHz, and stores the samples in a 256 long buffer. (to cope ...
1
vote
1answer
374 views

C programming language in every operating systems book [closed]

I am now reading two books: Tanenbaum - Modern Operating Systems Bach - The Design of the UNIX Operating System and I wonder why do they still mention programs written in C and functions from C ...
0
votes
1answer
429 views

How to perform argument parsing in C? [closed]

I am trying to write an utility that runs on linux Operating System. I am planning to develop it using C. I have lots of doubts striking me. I would like to ask some of it. Questions 1: How can I ...
1
vote
1answer
60 views

Repeated values for errno in man page

I'm looking at the man page for the libc function execve under Ubuntu 16.04. I'm trying to handle errors as described by the man page: RETURN VALUE On success, execve() does not return, on error -1 ...
0
votes
1answer
643 views

Serial Port Stream / Bash or C Script

I have a serial device (speed radar) that outputs data every 250ms. Here is the info I have on the device: 1. Speed Packet Protocol The Radar message packet consists of 7 bytes @ 1200 baud, no ...
0
votes
1answer
72 views

What means Port number usb-device command?

I going to write program with C++ for USB device and i going to display Port Number,when you type in your terminal root@raminfp# usb-device you will see in output : T: Bus=02 Lev=01 Prnt=01 Port=00 ...
0
votes
1answer
879 views

Alternative to timer_t in macOS

We are porting a linux app to macOS / iOS The app uses a timer wheel and timer_t type. This type is not defined in time.h class of macOS as described in: why is "timer_t" defined in "...
-2
votes
2answers
156 views

Reverse Kanji letters in the console

For an application I am develloping right now, (a shogi software), for text mode, i need to make upside down the graphics of the pieces , because the opponent's pieces are reversed. However, Unicode ...
0
votes
1answer
381 views

where does shared objects go after installing and how to find out their names

I just installed the SFML library using the following command: apt-get install sfml-dev and after installing it I went to my /usr/lib folder to find out what the actual shared object's name is (so ...
1
vote
0answers
188 views

How to create a device file and simulate behaviors of the Pseudo-devices?

I am trying to create a device that accept input and generate special output. To make it simple, say I want to create a device which accepts any input (like /dev/zero) and writes 00 ff 00 ff 00 ff .....
-4
votes
2answers
697 views

How to convert and Execute lib_file.a Library file in Command prompt?

I have a lib_file.a library file which is a static library and it is converted from .c file. I know how to compile and execute .c files. But I dont know how to execute Library .a file using command ...
3
votes
1answer
437 views

0–127 range limit on WEXITSTATUS in old Unix?

It is well known that, on many if not all Unixes, a process's exit status will be truncated to its lowest 8 bits when passed through _exit, waitpid, and WEXITSTATUS. (Current iterations of POSIX ...
3
votes
2answers
347 views

/usr/bin/time of a C program with I/O does not yield results

UPDATE I had very long lines in the file, and I put a newline after each 80th character (I used the sed command for that). Now the programs work fine. I can time them, and the results make sense. ...
3
votes
1answer
492 views

How does Node.js / the cluster module pass new connections from the master / parent process, to child processes?

How exactly does this work under the hood / at the OS level (primarily in Unix implementations / from the perspective of the sockets API)? The cluster module documentation says: "the master process ...
65
votes
7answers
19k views

Are threads implemented as processes on Linux?

I'm going through this book, Advanced Linux Programming by Mark Mitchell, Jeffrey Oldham, and Alex Samuel. It's from 2001, so a bit old. But I find it quite good anyhow. However, I got to a point ...
3
votes
2answers
1k views

Why is the env directory called before echo?

I am looking at a program coded in C. The issue with this program relies on this line of code. system("/usr/bin/env echo and now what?"); I understand that the system() just runs the command. But I ...
1
vote
1answer
257 views

adjtimex usage on Linux server

I want to change my system clock(rate - speed) on Linux server, Can I directly use adjtimex command from terminal like #adjtimex? or is there a specific syntax/script to call this command? Let me know ...
-2
votes
1answer
2k views

/dev/urandom returning same value every time [closed]

EDIT I: Windows subsystem for Linux. I bet I'm doing something wrong and/or really stupid. // random_problems.c #include <stdio.h> main(){ int rng; FILE * urnd = fopen("/dev/random", "r")...
5
votes
2answers
106 views

Is it possible to allow a background process to continuously output to terminal?

Here's a use-case to clarify my question. Say I have a calendar program that is set to run in ~/.bashrc, and it ensures the streaming output overwrites the same block of lines. Is it possible to have ...
0
votes
1answer
1k views

Undefined reference error to glib components even with glib included

Just starting out with Xubuntu 14.04 on a refurbished machine (2GB mem, 2GHz dual core), and have a cursory/reading knowledge of c, but am not a c programmer. I'm trying to compile code I found here ...
0
votes
2answers
464 views

Unable to smuggle data in username using custom pam module - input_userauth_request: invalid user

I am trying to get data into a process invoked via ssh by adding it the supplied username, e.g. ssh user@smuggledata@host I've written a PAM module, however sshd has already decided the user is ...
-4
votes
1answer
300 views

what is the error in the following code? [closed]

showing segmentation fault core dumped copying content of multiple files to one file the question is Write a C program that takes a string as an argument and search for all the files that begins ...
2
votes
1answer
324 views

Compiled Executable

If for example I have compiled a simple C program that uses GTK 3 on a machine running Ubuntu, will I be able to run it on other Linux flavours? Note: My actual questions is "Should I label my ...
2
votes
2answers
118 views

Race Condition not working on Arch Linux

The following C program is supposed to illustrate race condition b/w child and parent processes : #include <stdio.h> #include <unistd.h> #include <sys/types.h> int main() { ...
5
votes
2answers
2k views

Find out how many times a file has been opened?

Ok, here's a brain puzzle: how can I find out how many times a particular file has been opened (in any mode) by any / all processes currently running on a Linux machine? I.e. how many file descriptors,...
1
vote
1answer
128 views

Guide/Book recommendation for Kernel Newbies? [closed]

A book which will help non-real world c/c++ programmers, to step in kernel development.
-2
votes
1answer
841 views

Read standard library header file in terminal [closed]

is there any way to read a standard header file, say float.h , in terminal ? Sometimes it would be nice to know what are the names of some values, say max value of float or something like that.
1
vote
1answer
394 views

extract include in C file

I need to extract all included libraries in a C file, but I got some problems. My solution for this is so: grep -oP '#(?:\/\*\w*\*\/|)include(?:\/\*\w*\*\/|\s*)"\w*.h"|<\w*.h>' main.c This ...
0
votes
1answer
310 views

How to find PID of the process that owns a caught packet with libpcap in c?

Need to find the pid of the process that owns caught packet. Is there any way to do it without long parsing /proc/net/tcp and /proc/<PID>/fd/? Maybe, need to sniff packets in another way? I ...
2
votes
1answer
324 views

Pitfalls of calling system(3) or popen(3) with a constant string?

Assuming for a second that you explicitly set "problematic" environment variables like PATH, IFS, and possibly some of the LC_* variables, how bad of an idea is it to use popen and system with a ...
3
votes
1answer
2k views

How does fork system call really works

I've a very specific question about fork system call. I've this piece of code: int main (void) { for (int i = 0; i < 10; i++) { pid_t pid = fork (); if ( !pid ) { ...
1
vote
0answers
904 views

Read serial data continuously and store it in a file or buffer

I am trying to read data continuously from serial port and save it to a buf and/or to a file. Also this data is a stream of HEX characters and not ASCII. I am using a CHIP which runs debian. I have ...
0
votes
1answer
366 views

Everything is file or process - Linux [closed]

In Linux world, I learnt that there is corresponding file that user space program communicates with, in order to actually communicate with any hardware device , for example, below are the files for ...
4
votes
1answer
421 views

Custom link layer protocol in UNIX [closed]

I was wondering if someone has any info about how to implement a link layer portocol which uses the GPIOs (for example in a Raspberry Pi). The idea is to implement a custom interface (similar to eth0)...
7
votes
2answers
3k views

What are the .x files in /usr/include?

My /usr/include contains several files with the .x file extension, such as /usr/include/rpcsvc/rquota.x. They seem like C sources (running file /usr/include/rpcsvc/rquota.x results in C source, ASCII ...
1
vote
2answers
836 views

Sending String/Word/Characters through /dev/ttyS0 (RS232)

I am trying to send a string to the Serial Comm Port /dev/ttyS0 . On a Windows machine I use Turbo Basic program which has been working for many years. I can send '*80' and it turns on a light on ...
0
votes
1answer
1k views

Using system function call to execute a shell command [closed]

I am trying to make a few directories and files using the system call. ex) system("mkdir directory3"); I am having trouble getting started. This is what I have so far: #include <stdio.h> int ...
4
votes
2answers
674 views

Is it possible to query process information from Linux kernel directly?

I know pgrep, top, and ps all query /proc filesystems. So far so good. Yet what got me thinking is that in the past there was no /proc filesystem. Even nowadays, Mac OS X, as far as I know, has no /...
2
votes
1answer
2k views

Using strace for a C file

I have a C file that I want to trace what is going on. I'm trying to use: strace -o trace.txt random.c But it says that: strace: Can't stat 'random.c': No such file or directory I've been looking ...
3
votes
2answers
712 views

What's the difference between `mkdir -p` and `install -d`?

What, precisely, is the difference in what is being performed by mkdir -p and install -d, in terms of what changes the two commands are doing to the system?
1
vote
0answers
505 views

Is there a way to tune TCP about packet loss and retransmission?

In a question of mine ("Does arbitrary manipulation of TCP connection flow cause problems?") I asked whether a willing delay in a TCP connection could cause some troubles. My HTTP proxy, between a ...
-8
votes
2answers
4k views

How does the Conditional (ternary) Operator get evaluated? [closed]

in all of the examples I've seen how this works condition?value = true:value = false I have yet to find how it actually works. taking this mode of operation it is almost plainly explained. Short-...
1
vote
1answer
312 views

Difference between behaviors of setrlimit and limit stack

I am seeing a difference of behavior when setting stack size from shell and from inside my c program. The issue is that I have a function which has a large set of local variables (large arrays). If I ...
1
vote
1answer
6k views

Syntax error: “(” unexpected when execute a compiled c program

I try to execute the c binary file acqv program in the Shell (this program has been compiled like this on another computer : gcc acqv170104.c -o acqv `mysql_config --cflags --libs` the command line ...
1
vote
2answers
537 views

Sending signal SIGINT to process while executing system call or script by killall -SIGINT [closed]

I want to send SIGINT to all processes by name so I am using killall -SIGINT which was working fine. Now I introduced system() call in my c code to run a shell script or shell command which take ...
1
vote
2answers
776 views

Errors while compiling C code [closed]

I have found piece of C code which would be very useful for what I want do to under this link: All possible combinations of characters and numbers #include <stdio.h> //global variables and ...
3
votes
2answers
970 views

What is the advantage of archiving C object files in a static library (.a file)?

I mean, as opposed to just linking to individual modules/object files. Why are groups of modules archived together? Doesn't it make the executable 1. larger, and 2. less secure (i.e. more vulnerable ...
2
votes
2answers
2k views

fatal error: mcrypt.h: No such file or directory

I am trying to cross compile a C code which uses a header file mcrypt.h. I am compiling my code in Ubuntu distribution and my target is an openwrt distribution. I am getting the below error while ...
0
votes
2answers
65 views

Restore original string.h after accidental overwrite [closed]

I was reading the header files for c and by accident, i changed something (i deleted some stuff by accident) I closed out of sublime text editor, expecting it to ask me to save, but it saved ...