How to use fork() in Visual Studio 2015? (Windows 7 Professional) - c

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.

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

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.

Related

Is there a way to call the llvm `llc` command from my C project?

I'm trying to use the llc command from llvm in my C compiler project, but I don't know how to use it. I've tried linking llvm libraries in cmake, but I don't know which libraries to link if I want llc. Any help would be fine, thanks!
Now it kind of depends on the OS, but yes there are ways to open a subprocess through the system shell
Under UNIX-y systems you can use popen (https://linux.die.net/man/3/popen), which allows you to open and communicate with a subprocess (in this case llc).
Under Windows it seems like _popen has similar functionality - though I've never personally used it so you may need to read the MSDN

Including basics library of C (unistd.h) on window

I've been programming at my school on a Mac for one month. We did C programming on an UNIX shell.
Now i'm back at home and I use my own PC that is on window 10. I have tried to make a similar set up, but i don't know much about all that. I installed git and bash, this made it like a UNIX shell. Also I have installed the gcc compiler.
So, now that i'm making a basic program, it should be working but when I make the include <unistd.h>, the shell can't find it.
I know my question is probably silly but I really couldn't find how to solve the problem. I downloaded the unistd.h file.
I also found this http://processors.wiki.ti.com/index.php/Compiler/diagnostic_messages/5
It explain that i should be putting the .h folder in some kind of defined path, but I don't know how to do that.
Does anyone know how I can fix this?
If you installed gcc as part of mingw or something similar, it should have included a unistd.h. Just having the gcc compiler is not likely to get you very far.
You probably want to start over and install something different than you did (mingw or cygwin or just set up a vm as suggested) that provides a more complete environment.

Can you code a shell for Linux using Windows OS and Dev-C++ IDE? Do shells work the same way for both operating systems?

I'm studying computer engineering and we have a class called operating systems where they lecture us about how OSes handle stuff etc. This week we were given a homework which requests us to code a shell that works on Linux. The problem is, they tought us literally nothing on how to code a shell so we are supposed to do some research and figure it out.
I found this guide online and it seemed perfect to me: link
Code, with explanations, what else could I ask for.
Now, I'm using a Windows PC and I use Dev-C++ IDE with GCC compiler. Can I code a shell that works on Linux with my current setup or do I have to install Linux? Are there any major differences between how shells run on these OSes?
If you want to write a shell for Linux, you want to target GNU/Linux which is basically POSIX with some extensions.
Dev-C++ by default uses MinGW GCC as its compiler, providing a Win32 API.
Win32 and POSIX are completely and fundamentally different. A shell written for one will not even slightly resemble the other.
Instead, you have several options:
Dev-C++ can optionally use Cygwin GCC, providing a more GNU/Linux-like experience on Windows. You need to take great care not to rely on any Cygwin-specific functionality like how it automatically translates pathnames and line terminators. You'll still need access to a Linux install to verify that it works.
Windows 10 lets you install WSL, a more modern Linux compatibility layer for Windows. Dev-C++ doesn't explicitly states it support it, so you may need to edit and compile separately, and may lose debugging functionality. You'll still need access to a Linux install to verify that it works.
Just run Linux in a VM. The only thing to care about is getting your shell working.
I would suggest saving yourself a ton of trouble right now and just download/install an Ubuntu image in VirtualBox.

How can I compile C files into an executable (.exe) file?

I am unsure about compiling C files into executables by using Cygwin under Windows 7.
Can anyone please tell me how to do this?
I've read some tutorials but still don't get it. I understand that I need a Makefile, but what shall I write into it to have an executable file after the compilation process?
For the beginning I would say it is enough to Install MinGW. If you have installed it you find in the bin folder a gcc.exe which is the Compiler. Either set the PATH Variable to the bin folder or go directly to this folder.
In terminal use:
gcc your_C_file.c
The output will be an exe.
There are several ways to compile c-files. Makefiles are just one possibility. But as you proposed it... Here are two tutorials for Makefiles:
http://makepp.sourceforge.net/1.19/makepp_tutorial.html
http://mrbook.org/tutorials/make/ (Content from 2012 accessable via waybackmachine)
But note, that you will also need a compiler (installed under cygwin).
Another possibility is to use Dev-C++, a IDE (Integrated Developement Environment) for C++. Once installed you can create a project and add your source code, and just compile the project. It also contains a c++ compiler (also supports C), which is named mingw. The makefile needed is automatically generated. So that's simpler for beginners.
You can download Dev-Cpp here: http://www.bloodshed.net/devcpp.html
Note: As you spoke about cygwin I assume you use Windows. Dev++ works only under windows, and you wont need cygwin.
Q: How can i compile c-files into an executable (.exe) file?
A: Get and use a C compiler.
GCC/Cygwin is one possibility. MS Visual Studio is another: you can download the free "MSVS Express" here: http://www.microsoft.com/visualstudio/en-us/products/2010-editions/express.
How you interact with the compiler is another question.
You can certainly use a command line.
You can use a command line with or without "Make": you can let "Makefiles" do the "heavy lifting" for you, you can use .bat files, or you can type everything by hand.
Using a graphical IDE is another possibility. "Eclipse" and "MS Visual Studio" are two popular alternatives for Windows.
Even easier solution is A86 Assembler. Its old school but works perfectly, in the right hands ;)

How to use crypt(3) in windows?

How can I invoke crypt(3) from a c program on a windows platform? I can't find a header file to include. I have MinGW with gcc and msys installed.
Edit: as an alternative, I would also accept a way to call this function (or an equivalent) from Visual Studio.
Have you seen this? http://sourceforge.net/projects/mingw/files/MSYS/crypt/
I suppose you may be missing it, or just don't realize you have it, but it seems like the answer, and I found it by typing "crypt mingw" into Google.

Resources