Questions tagged [unistd.h]

unistd.h is a C/C++ header files contains needed to provide access to the POSIX operating systems

Links:

https://en.wikipedia.org/wiki/Unistd.h

https://pubs.opengroup.org/onlinepubs/009695399/basedefs/unistd.h.html

175 questions
217
votes
10 answers

Is there a replacement for unistd.h for Windows (Visual C)?

I'm porting a relatively simple console program written for Unix to the Windows platform (Visual C++ 8.0). All the source files include "unistd.h", which doesn't exist. Removing it, I get complaints about misssing prototypes for 'srandom',…
AShelly
  • 34,686
  • 15
  • 91
  • 152
41
votes
3 answers

Cannot open include file: 'unistd.h': No such file or directory

After having installed libpng into my computer, I've included it into my project using #include on a Windows 7 SP1 plateform and using Visual Studio Ultimate 2013. But at build time, I'm getting this error: C1083: Cannot open include file:…
user3471387
  • 427
  • 3
  • 8
  • 10
30
votes
2 answers

How to call execl() in C with the proper arguments?

i have vlc (program to reproduce videos) if i type in a shell: /home/vlc "/home/my movies/the movie i want to see.mkv" it opens up an reproduces the movie. however, when I run the following program: #include int main(void) { …
Matias Morant
  • 513
  • 2
  • 5
  • 12
14
votes
3 answers

clang++: fatal error: 'unistd.h' file not found

Using OS X 10.10.2, I download Clang for Mac OS X v. 3.6.0, and try to compile a simple Hello World program. The commands I use are these: (assumes you downloaded clang to .) cd . ./clang+llvm-3.6.0-x86_64-apple-darwin/bin/clang++ main.cpp The…
user4664340
13
votes
2 answers

What is the difference between fsync and syncfs?

What is the difference between fsync and syncfs ? int syncfs(int fd); int fsync(int fd); The manpage for fync says the following : fsync() transfers ("flushes") all modified in-core data of (i.e., modified buffer cache pages for) the…
cominfotty
  • 441
  • 1
  • 6
  • 10
13
votes
4 answers

C sleep function not working

When including the sleep function from unistd.h the program hangs indefinitely: #include #include int main() { int i; printf("0 "); for(i = 1; i <20; ++i) { sleep(2); …
James Jenkinson
  • 1,563
  • 2
  • 16
  • 33
12
votes
3 answers

Fast input/output in competitive programming

I have come across this particular snippet of code many times in solutions of competitive programming contests. I understand the basic use of this code to beat time limits but i want to understand it more deeply. I know that unistd.h gives access to…
s2n
  • 327
  • 3
  • 9
8
votes
1 answer

Difference between unistd.h and sys/types.h in linux

When I have searched for the header unistd.h, in The Open Group, I found that it contains the standard symbolic constants & types and for sys/types.h it said for data types. Then I found that both have uid_t, pid_t and several similar types. I am…
user3511557
7
votes
3 answers

redirecting standard output in c then resetting standard output

I'm trying to use redirects in C to redirect input to one file and then set standard output back to print to the screen. Could someone tell me what's wrong with this code? #include #include #include int main(int argc,…
David
  • 2,080
  • 5
  • 29
  • 44
7
votes
1 answer

execl crashes C++ node.js-addon

As normal C++ execl works fine (compiling with g++ ok.cc -o ok.elf) #include int main(){ execl("/usr/bin/python", "/usr/bin/python", nullptr); } But crashes, when works as node.js C++ addon #include #include…
7
votes
1 answer

Attempting to use execvpe(...) but get implicit declaration error - even though I think I'm using the correct argument types

I am getting the following warning when I compile: execute.c:20:2: warning: implicit declaration of function ‘execvpe’[-Wimplicit-function-declaration] execvpe("ls", args, envp); ^ My understanding is that this occurs when the function you are…
newbie
  • 607
  • 2
  • 8
  • 16
6
votes
4 answers

unistd's execl() without passing any arguments

In my code I need to execute /bin/bash, but I wan't to do it without passing any arguments to it. I wrote this: execl("/bin/bash", NULL); Then, through some research, I realized that I also need to add type cast: execl("bin/bash", (char*)…
Błażej Michalik
  • 4,474
  • 40
  • 55
5
votes
2 answers

Race condition during file write

Suppose two different processes open the same file independently, and so have different entries in the Open file table (system-wide). But they refer to the same i-node entry. As the file descriptors refer to the different entries in the Open file…
arka
  • 418
  • 2
  • 9
5
votes
3 answers

What does #define __REDIRECT_NTH do in unistd.h?

GNU unistd.h has this bit of magic: /* Move FD's file position to OFFSET bytes from the beginning of the file (if WHENCE is SEEK_SET), the current position (if WHENCE is SEEK_CUR), or the end of the file (if WHENCE is SEEK_END). Return…
vy32
  • 28,461
  • 37
  • 122
  • 246
5
votes
1 answer

What does libc_hidden_proto in the glibc standard libraries do?

I was trying to look up the prototype for the getpgrp() function in unistd.h but couldnt find it. The only line containing getpgrp in that file was the line libc_hidden_proto (tcgetpgrp) and I'm assuming this is a macro, but I dont know what it…
Jerry Marbas
  • 185
  • 7
1
2 3
11 12