Episode #125 of the Stack Overflow podcast is here. We talk Tilde Club and mechanical keyboards. Listen now

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
241
votes
4answers
91k views

Why is FreeBSD deprecating GCC in favor of Clang/LLVM?

So I was surfing the net and stumbled upon this article. It basically states that FreeBSD, starting from Version 10 and above will deprecate GCC in favor of Clang/LLVM. From what I have seen around ...
106
votes
10answers
20k views

Why does argv include the program name?

Typical Unix/Linux programs accept the command line inputs as an argument count (int argc) and an argument vector (char *argv[]). The first element of argv is the program name - followed by the actual ...
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 ...
41
votes
5answers
148k views

How do I kill all a user's processes using their UID

I want to kill all running processes of a particular user from either a shell script or native code on a Linux system. Do I have to read the /proc directory and look for these? Any ideas? Is there a ...
9
votes
1answer
5k views

/dev/tcp not present in Linux

I am porting C/pro*c code from UNIX to Linux. The code is: #define __NFDBIT (8 * sizeof(unsigned long)) #define __FD_SETSIZ 1024 #define __FDSET_LONG (__FD_SETSIZ/__NFDBIT) typedef struct ...
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
votes
1answer
267 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 , ...
22
votes
4answers
19k views

After fork(), where does the child begin its execution?

I'm trying to learn UNIX programming and came across a question regarding fork(). I understand that fork() creates an identical process of the currently running process, but where does it start? For ...
12
votes
2answers
6k views

Why can't I run this C program?

I'm trying to run my first "process" program, but I get the following error : ./fork.c: line 4: syntax error near unexpected token `(' ./fork.c: line 4: `int main()' I'm pretty sure that the code is ...
2
votes
1answer
154 views

How is the C library able to access environment variables?

How do functions like getenv(3) access the environment when my program doesn't have any references to the environment?
5
votes
4answers
3k views

Is there any manual about C in Linux? If any, what is it?

While I find that we can read some manuals about Library calls (C library functions) & acsii in Linux. But I still do not find any manual about C precedence order so far. So you can recommend ...
3
votes
2answers
844 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 ...
4
votes
1answer
12k views

Changing a user's default shell

I have created a simple C shell on my local Linux server. I am trying to learn how to change the default shell of another user (bob) to be this new C shell that I have created. Is it possible to ...
4
votes
2answers
3k views

How to view Core file (general)

Scenario (Ubuntu 16.04): I compile and run a C program (with -g, I get the traditional Segmentation Fault (core dumped), and then (of course) there is no mythical "core" file to be found. Some ...
1
vote
2answers
748 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 ...
23
votes
2answers
67k views

Default stack size for pthreads

As I understand, the default stack size for a pthread on Linux is 16K. I am getting strange results on my 64-bit Ubuntu install. $ ulimit -s 8192 Also: pthread_attr_init(&attr); ...
37
votes
6answers
28k views

How to dump a binary file as a C/C++ string literal?

I have a binary file I would like to include in my C source code (temporarily, for testing purposes) so I would like to obtain the file contents as a C string, something like this: \x01\x02\x03\x04 ...
50
votes
4answers
12k 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 ...
10
votes
10answers
5k views

Development environment for C

Looking for ideas on setting up a convenient and productive development environment for C development. I found C editing with Vim very helpful but I would like to get a wider sampling of suggestions.
22
votes
3answers
30k views

How does copy-on-write in fork() handle multiple fork?

According to Wikipedia (which could be wrong) When a fork() system call is issued, a copy of all the pages corresponding to the parent process is created, loaded into a separate memory location by ...
4
votes
1answer
3k views

Sparse files/file holes and unexpected block size

For my own learning, I've been playing around with creating files with file holes. I created a util that simply reads from stdin and writes to a file, but before writing to the file, it uses lseek to ...
4
votes
2answers
2k views

How to adjust time command to measure a program elapsed time

I'm trying to get the time that my program takes to finish (aka elapsed time) so I'm using the common time. What I get by doing this is 3 measurements: user, system and total. This is fine but I ...
9
votes
1answer
6k views

why is “timer_t” defined in “time.h” on Linux but not OS X

While I was reading a C source code files, I found this declarations. (This source code was written for linux system program. This is very important information) #include <time.h> #include <...
5
votes
2answers
1k views

How to programmatically retrieve the GID of a running process

I need to write some C code to check the effective GID of a running process whose PID I know. I've not found any direct way to do this. There are a number of heavyweight kludges I could use, such as ...
4
votes
2answers
789 views

linux setuid does not work

I am learning linux suid,so I have written a small c program with the following content to test it #include<stdio.h> int main(){ system("echo 100 >> test.txt"); return 0; } -rwsr-xr-x 1 ...
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
1answer
445 views

Linux kernel 3.2 syscalls [closed]

Just trying to get the assembler instructions for <__execve> of the code below because i want to build the shell spawn opcode list: #include <stdio.h> int main() { char *happy[2]; ...
0
votes
0answers
38 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 ...
12
votes
3answers
50k views

convert executable back to C source code

Unfortunately I lost my source code and I just have the output file that made with gcc in linux and I don’t have any access to my pc now.is there any way to convert output file to source file (in c ...
9
votes
2answers
4k views

Get output of `posix_spawn`

So I can run a process in Unix / Linux using POSIX, but is there some way I can store / redirect both the STDOUT and STDERR of the process to a file? The spawn.h header contains a deceleration of ...
9
votes
3answers
2k views

“which” equivalent for shared libraries

I am looking for a utility that would behave in the same way as which, but to look up shared libraries (*.so) in the directories defined in $LD_LIBRARY_PATH?
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; } ...
6
votes
2answers
13k views

How to find the header file where a c function is defined?

Is there an easy way to find out which header file a C function declaration is in? cding into /usr/include and running (grep -E 'system.*\(' *.h -R) works with some trial and error, but isn't there an ...
5
votes
2answers
3k views

How to create GUIs (such as menuconfig) with lxdialog

I try to generate a menuconfig by my own with the help of lxdialog (source: lxdialog). Unfortunately this is not so well documented as I wished for. Example: So what I did: I included these files (...
4
votes
3answers
2k views

How to debuild (Debian) Apache without it performing a clean

I am trying to edit an Apache module on Debian (strictly, I'm doing this on Raspbian Jessie-Lite), and am broadly following the Debian build instructions: $ mkdir -p ~/src/debian; cd ~/src/debian $ ...
4
votes
1answer
4k views

Start 4 programs on startup in Linux Mint via terminal

I'm working on a project and I hope you can help me solve a problem. I have four programs that are written in C. They have been compiled using gcc and they work as they should. Because the four ...
3
votes
1answer
7k views

mount overlayFS as Read-Write FS

I want to mount my RO Filesystem using overlayFS - in order to use two layers FS (Lowerdir and Upperdir). I tried the following mounting command - mount -t overlayfs -o lowerdir=/,upperdir=/overlay "...
3
votes
3answers
12k views

/usr/ucb/cc: language optional software package not installed

I tried to compile some C code to get object file from a shell prompt: $cc a.c But this gives me the following error: /usr/ucb/cc: language optional software package not installed How can I ...
2
votes
2answers
2k views

USB Driver Compilation Error

I'm currently trying to compile a Linux USB UART driver, which is provided here: http://www.exar.com/connectivity/uart-and-bridging-solutions/usb-uarts/xr21v1410 The driver consists of 2 header files ...
2
votes
1answer
4k views

How do I manually modify an inode?

I am using Ubuntu Linux and, just for fun, I want to create a hardlink to a directory (as seen here). Because I'm just doing this for fun, I'm not looking for any sort of pre-developed directory-...
2
votes
2answers
2k views

Linux System calls in C on OSX

So I did a quick test and #include <sys/types.h> #include <unistd.h> #include <stdio.h> int main (int argc, char *argv[]) { printf("Hello World\n"); printf("%d\n",...
1
vote
1answer
177 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
4answers
3k views

I can not get my Realtek 8723 driver source compiled

I have a Lenovo IdeaPad Yoga 13. WLAN won't work out of box with fedora 18. So I googled around and found this 2 links: https://askubuntu.com/questions/139632/wireless-card-realtek-rtl8723ae-bt-is-...
1
vote
1answer
1k views

Building shared library which is executable and linkable using Cmake

How to create an executable shared-library using cmake? Something like: libtest.so :: linkable shared library libtest.so :: executable too Note: gcc/g++ options are known to achieve the ...
1
vote
1answer
297 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
votes
2answers
189 views

Why rsh not opens and reads PAM modules and limits.conf?

I am working on a project, that uses rsh utility for remote connection. But my project needs some extra features for that, so I add that features. Till now, all the things are going fine. But when I ...
-1
votes
1answer
762 views

C compiler while installing GCC!

I have a virtual machine running RHEL7. I am trying to install GCC from source following https://gcc.gnu.org/wiki/InstallingGCC I am unable to do yum groupinstall "Development Tools" or yum ...