Difference between linux and windows process - linux

In linux we create a process using fork and exec ant while in windows we use createprocess .My teacher told that linux method of creating process is more robust than windows why?

Fork & exec are direct calls to the kernel whereas createprocess goes through window api to access kernel.
There might be more various reasons but this is what I have on top of my mind :)

Related

Killing a process windows CE

I need to implement a program that will run on Windows CE 6.0, in C++, and that aims to kill a specific process at a specific moment.
I have tried to use 'TerminateProcess(ProcessHandle, ExitCode)'. It works, and kills the process whose handle I passed. However, when killing the specific process I want to kill, the machine stops responding, which is not acceptable.
I can kill the process via tellnet, if I use:
telnet 10.120.12.5 (IP of the Windows CE machine)
shell -d
kp 6522589 (example ID of the proccess)
That works. It kills the process and the machine does not stop running.
So the question is, how can I insert this command into my code? or, how can I call a script which does this from my code? (the script will have to be stored inside the windows CE machine).
Any other suggestion will be welcome.
How do you get the ProcessHandle? You usually need to free it with CloseHandle() after you are done with it (after calling TerminateProcess()).
You can use CreateProcess() to run another program, e.g. the shell/kp program.

Linux command on wake up from hibernate/suspend

I'm new to Linux and running Mint. I've seen a lot of documentation on creating commands that run when the os is started up from the computer being powered off. Is there a way to make similar commands to run when the os wakes up from hibernate or suspend? (For context, I'm running 'rfkill block bluetooth' on startup and would like to when my pc wakes up from hibernate as well).
place your commands in a script file and ensure you have sufficient owner/permissions to execute in /lib/systemd/system-sleep/ so once your OS suspends from sleep, its going to execute.
For more information
man systemd-sleep
https://askubuntu.com/questions/226278/run-script-on-wakeup

Detect new process creation instantly in linux

I am trying to create an application in userspace that sets affinity of processes. I would like the program to be triggered immediately every time a new pid/tid is spawned by the kernel. I am attempting to write to a file node under /proc from the do_fork() method in the kernel but I feel that it may have too much overhead.
Does anyone know any alternatives to detect a new process creation immediately after it is spawned?
If monitoring do_fork() is the way to go, would a call back to an userspace program via a system call be faster that using a fs node to communicate?
Forkstat is a program that logs process fork() [among other things]
Install it:
$ sudo apt-get install forkstat
Use it to log "fork" events:
$ forkstat -e fork
Use a socket with NETLINK_CONNECTOR. The kernel will tell you about process events, including fork()s and exec()s. You must have CONFIG_CONNECTOR and CONFIG_PROC_EVENTS enabled in your kernel.
Here's a related question with more details:
Detect launching of programs on Linux platform
For a complete socket NETLINK_CONNECTOR example, see:
http://bewareofgeek.livejournal.com/2945.html
As an aside, Inotify doesn't work. It will not work on /proc/ to detect new processes:
https://bugs.launchpad.net/ubuntu/+source/linux/+bug/454722
execsnoop can be a good alternative to show new processes and arguments.

How to debug windows executable in Linux

I am using Ubuntu 13.10. Is it possible to debug a windows executable under Linux?
I've tried gdb, but it always throw me this error message.
/bin/bash: line 0: exec: /some.exe: cannot execute: Permission denied
I don't have much experience with this but, I think, what you're looking for is winedbg. Initially, it should allow you to debug Win32 applications in Linux.
I suggest you try the IDA Debugger (cross platform debugger).Hope it helps.
You are trying to execute a program designed to run in a OS, from within another one, which could be using a complete different processor than a x86.
In order for a executable program to be run in a specific OS, these modules or services must exist:
A module that can understand the binary code of the executable program and translate, if needed, into binary code of the host processor.
A service that can intercept any instruction identified as a system call, and emulate its behaviour using host resources
A module that is able to load, parse and prepare a process block to acommodate the new "guest" process
This is just for executing a program. To debug it, you also need a service that can interact with the above mentioned modules/services in order to control execution of that program.
That said, you can probably debug an EXE file using some utility from the Wine project, asumming your Ubuntu is running on a x86 processor. Take a look at it.
http://www.winehq.org/
Also, I recall VirtualBox offers some sort of debugging help for processes running on the guest OS, but I'm not sure about this.
No, it is NOT possible to debug a Windows executable under Linux.

Launch process from CGI in Linux

I need to launch server executables from terminal. They are running through wine (because those executables are for Windows) in the background. If I launch them normally, from Terminal, those work without any problem.
Now I'm trying to make CGI (bash) script and launch servers from website, but script doesn't launch processes. I thought that it has something to do with wine, but no, script doesn't launch any processes at all.
I'm building that system on Ubuntu 12.04.1 LTS, after that scripts would go onto Debian server.
So, the question is: is it even possible to run background process from CGI scripts? If yes, would you please explain how?
A CGI program is like any other program, except that it is supposed to run quickly and to follow the CGI protcol (in particular, regarding to stdout output).
As with any other Linux program, you can (subject to limitations and permissions on your system) run processes, using syscalls like e.g. fork(2), execve(2) and many others.
I suggest to read a good Unix programming book like Advanced Unix Programming abd Advanced Linux Programming. We can't teach all that here in a few minutes.
You could also run processes using the library system(3) and popen(3) functions (of course these functions are implemented using syscalls, inside GNU libc)
Don't forget the stateless property of CGIs; you may consider using FastCGI or SCGI instead.
(A program started thru wine from a CGI might fail, e.g. because it has no X11
server to talk to; For C# programs, consider Mono on Linux).
Another possibility could be to run Windows in some VM, and have your CGI interact with such virtualized Windows programs. Not knowing Windows, I have no idea about the issues of such an approach.

Resources