2

I searched around and all I could find was that I needed Cygwin. I installed it but I can't seem to find unistd.h anywhere in C:\cygwin64\usr\include. Of course, I added that path to the "Include Directories" in my Project in VS2015.

What I want to do is be able to use fork() and execv() (or maybe execl(), execlp(), execvp() etc...) in C. I know the easy solution is just "Go do it in Linux" but VS2015 makes it easier to code correctly.

What I think I should do is, I should install something else from Cygwin which would include the headers I need, I just don't know how and where to find them, so I'm asking your help.

  • Why do you want to use `fork()`? Why not just use win32 api? – Junyoung Clare Jang Dec 10 '16 at 14:42
  • It's this project I have to do for one of my classes(Operating Systems), and we have to learn fork and exec. – Angelino Mehmeti Dec 10 '16 at 14:45
  • I use [`_beginthread`](https://msdn.microsoft.com/en-us/library/kdzttdcb.aspx). AFAIK MSVC does not have `fork`. – Weather Vane Dec 10 '16 at 14:47
  • @WeatherVane I strictly have to learn to use `fork()`, I'm supposed to do this project in Linux, i just code it in `VS2015` and then I will copy it and run it in Linux. – Angelino Mehmeti Dec 10 '16 at 14:49
  • 1
    You can't compile it with MSVC, because MSVC does not know what `fork` is (AFAIK). – Weather Vane Dec 10 '16 at 14:50
  • Oh. you misspell it. not `user` but `usr` – Junyoung Clare Jang Dec 10 '16 at 14:51
  • [This](http://stackoverflow.com/questions/23985600/using-fork-with-vs-2013-and-cygwin) guy's response to the best answer indicates that he managed to do it, though. – Angelino Mehmeti Dec 10 '16 at 14:51
  • @JunyoungClareJang Thanks, I did indeed . I didn't in VS2015 though, haha. edit: I edited it. – Angelino Mehmeti Dec 10 '16 at 14:53
  • Ye, actually, you can use`fork()` with cygwin. My first comment is just for "why do you so eagerly want to use fork?". Now I got it. – Junyoung Clare Jang Dec 10 '16 at 14:54
  • @JunyoungClareJang Which is my path? – Angelino Mehmeti Dec 10 '16 at 14:56
  • Cygwin is not MSVC, but please this [comment from @duskwuff](http://stackoverflow.com/questions/23985600/using-fork-with-vs-2013-and-cygwin#comment36959922_23985600) in the question you linked. – Weather Vane Dec 10 '16 at 14:56
  • I think you didn't install gcc, am I right? – Junyoung Clare Jang Dec 10 '16 at 14:56
  • @WeatherVane I mean, you can use `fork` **in VS** with cygwin – Junyoung Clare Jang Dec 10 '16 at 14:58
  • Just forget about path comment. I just mean path in your question. – Junyoung Clare Jang Dec 10 '16 at 14:59
  • @JunyoungClareJang Sorry for my ignorance, but all I know is I installed VS2015 and I never had a problem in earlier years making projects that used simple libraries like `stdio.h` , `stdlib.h` etc. Now I see it gets a bit more complicated that I need to use libraries that are not meant for Windows, but I'm hoping I can find a way around it. Honestly, I can't answer your question, because I don't know the answer. – Angelino Mehmeti Dec 10 '16 at 15:01
  • Hm... I mean, you can install program **gcc** in your cygwin, but according to what you said, you didn't install it, right? Then install it from cygwin first. After that, you can see some headers in cygwin directory. – Junyoung Clare Jang Dec 10 '16 at 15:04
  • @JunyoungClareJang For the last 15 minutes that I haven't answered, that's what I have been doing. I will come back with another question probably, when I'm over with installing **gcc**, since everything goes wrong when you want to code something :D – Angelino Mehmeti Dec 10 '16 at 15:22
  • Even you installed it, there are no files in include directory? It's weird. It's something must not be happened. – Junyoung Clare Jang Dec 10 '16 at 15:30
  • 1
    @JunyoungClareJang No no, I'm not over installing it, I'm re-installing Cygwin right now and for some reason its taking a hell of a long time. I think I didn't install any packages the first time, and now it's installing all of the default ones or something. When i finish installing **gcc** I will go to VS2015 and make it use **gcc** , after that I will check what is up with the libraries, and IF i have a problem again, I will come back here and update you :D – Angelino Mehmeti Dec 10 '16 at 15:52

2 Answers2

2

fork(),execv(),...etc all are linux OS commands which won't work in windows.. so either u should try in a linux system or use a virtual window to use linux system.

  • As I already said `I know the easy solution is just "Go do it in Linux" but VS2015 makes it easier to code correctly.` I'm just hoping there is a way to that in Windows 7. Actually what I really want is Visual Studio to understand what I'm typing, when i type `#include ` or `pid_t pid;` etc. I want to see an error only when I have actually typed something wrong. Right now if i type `#include `, include will be underlined with red colour and say "cannot open source file "unistd.h" ". – Angelino Mehmeti Dec 10 '16 at 15:57
2

unistd.h is a unix file. You can't use it on Windows

PSS
  • 21
  • 4
  • This does not provide an answer to the question. Once you have sufficient [reputation](https://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post;](https://stackoverflow.com/help/privileges/comment) instead, [provide answers that don't require clarification from the asker](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). – mrun Mar 01 '18 at 08:14