linyuwang
linyuwang

Reputation: 319

How to use <unistd.h> library in visual studio?

I am faced with a OS experiment to develop a Unix shell. In order to create a new process, I have to use the fork() function. However, the fork() function is defined in <unistd.h>, and I can not use it in Microsoft Visual Studio. Is there any way to solve this?

Upvotes: 0

Views: 8089

Answers (2)

Ilan Kutsman
Ilan Kutsman

Reputation: 469

io.h is the Visual Studio equivalent of unistd.h.

Upvotes: 4

jpo38
jpo38

Reputation: 21514

If you are using Visual Studio, it probably means you are targetting Windows...? fork() is not part of Windows API, you must then find another way to create a new process:

  • Directly use Windows API: CreateProcess
  • Use a cross-platform library (that will callCreateProcess on Windows and probably fork on Linux. Have a look at Boost.Process for instance (but there's probably others, like Qt's QProcess

I would personnaly recommand the second approach (I use Boost.Process).

Upvotes: 1

Related Questions