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
4
votes
1answer
416 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
331 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
463 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 ...
61
votes
7answers
17k 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
231 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
98 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
981 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
425 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
290 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
275 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
114 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() { ...
1
vote
0answers
151 views

Implement own shell [closed]

I am trying to implement my own shell. I have a few questions about my code and about tasks to resolve. Below I present my previous code and questions: #include <stdio.h> #include <stdlib.h&...
5
votes
2answers
1k 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
125 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
725 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
343 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
261 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
298 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
1k 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
827 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
342 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
391 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
717 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
613 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
625 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
481 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
3k 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
243 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
490 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
666 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 ...
2
votes
2answers
867 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
63 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 ...
0
votes
2answers
772 views

Can't run the exe file [closed]

I have a code (.c file). And used the following command; #!/bin/bash # gcc file.c -o file.exe #./file.exe So when I try to run the .exe file (using Wine) I get an error which says "wine: Bad ...
2
votes
1answer
64 views

How to see which files a Makefile uses?

I have the following makefile which is supposed to build procdriver.c and thus output a .ko file. The issue is that even when I delete procdriver.c my makefile seems to be able to build a procdriver....
3
votes
0answers
86 views

C on Linux: Running 25 parallel processes is significantly quicker than running 24 [closed]

My C-program uses fork() to create new processes and I measure the time it takes for each one of these processes to do its work. In fact, I let them do the work 10000 times and measure that time. ...
1
vote
1answer
715 views

How can I create my own custom progress bar in Conky?

I have started using Conky some days ago, and I'm willing to create my own configuration. I have added some colors, cool ASCII art and learned the basics. However, I don't like the default progress ...
1
vote
1answer
988 views

How to get the REAL gcc (not the one that is hashed to clang) in MacOS?

I am trying to compile a program that uses the OpenSSL library. I had a problem where it couldn't find the header files. I fixed this problem by adding the option -I /usr/local/opt/openssl/include ...
3
votes
1answer
263 views

du command showing different results than st_blocks

I'm implementing du -a in C and I'm using the stat function for this. The problem is that what I get from using st_blocks is 2× what I get when I use the command itself, does this make any sense? or ...
0
votes
1answer
108 views

Automate list files with ssh from Ubuntu to Windows(Openssh)

I am writing some automation API in C working with remote file system via SSH. The host is running Ubuntu-Linux and one of the target machine is running Windows 7 with OpenSSH installed. The ...
1
vote
1answer
296 views

Entering ascii chars as program input

If I write a very simple C terminal program that takes an input, how can I enter an ascii character as the input, like for instance the backspace character?
0
votes
1answer
476 views

Why is directing stdout to a file inconsistent and delayed? [duplicate]

I have tried two methods to direct the output of a program's printf calls to a file. In both cases, sometimes the file is updated immediately, sometimes it takes several minutes, and sometimes it ...
1
vote
0answers
53 views

some characters show after put objects on amazon s3

I use libcurl to put objects on amazon s3 service. Here is my original contents in a.txt: aaaaaaaaaaaaaaaaaaaaaaaaaaa bbbbbbbbbbbbbbbbbbbbbbbbbbb ...
0
votes
1answer
256 views

Where is struct blkid_struct_dev defined?

blkid.h typedefs as follows: typedef struct blkid_struct_dev *blkid_dev; That is the only appearance of the token blkid_struct_dev in blkid.h. grep -rl blkid_struct_dev /usr/include returns only /...