I am trying to write a programs that is processing data. And for example I want to run 5 of them and they can run in parallel.I have already written shell like program with lexer and parser but I don't know how to manage these processes. Can anyone give me any tips because I'm stuck and have no idea what to do next?
I think you're looking for fork(), wait() and pipe()
You can find tons of examples if you google with those keywords. Hope it helps.
Related
I am trying to create two new system calls for the Kernel, to set and get deadlines.
I know the general concept, but I am struggling as to what the .c files will look like.
Could anyone give me some examples as to how, given a process's pid, give it a soft/hard deadline.
Also, if possible I'd like to know how I can examine if a process is child of another process or not.
Are there any limitations using a C 'shell emulator' in this way for a user to send commands to the kernel (in linux)? As an afterthought question, if you set a user to not have shell access, what stops them using something like this to interact with the kernel? (by say running the program from shell_exec via php)?
(by restricting the user, I mean in /etc/passwd)
Thanks
Okay, there are several issues here.
First off, popen isn't terrifically satisfactory as a way to emulate a shell, because you won't be able to create your own pipelines and you'll constantly be fighting permissions and things like that.
Second, popen doesn't protect you particularly against malicious commands anyway.
What you really want is to use a restricted shell.
Update
In answer to your second question, pretty much nothing. Which is why you should use that with great care.
I am a student and I'm taking a course where my project is to write a server using unix sockets, threads or epoll, and so forth.
However, as the client takes his input from the user, I wanted to go an extra mile and give it some sort of memory for the commands he has given in the past; like the shell or gdb has.
I have no idea how to do this, can you guys help me? I put ncurses in the title because I suspect I'm supposed to use it, but I don't know how, I never used ncurses before.
The GNU readline library provides this functionality.
I have a process that seems to be hanging on solaris, I have tried to attach to the process using GDB to see what it is doing but no luck.
There is no error from what I can see, it is just sitting there...
Are there any other tools or techniques I can use to see what the process is stuck on?
Thanks for the help
Lynton
pstack <pid> will print you what all the threads within this process are doing (full stack traces, including function names, if your binary is not stripped.
truss is Linux's strace equivalent. It will show all the system calls that the process is doing. It might help you in debugging.
DTrace is a great debugging swiss-army-knife that can show you pretty much anything you can think of. The downside is that it needs to be run with root permissions on a global zone. It takes some time to learn, but it's time well worth spending.
Use powerful dtrace facility.
Here the short introduction how to trace user processes.
I have a very nice idea for a kernel patch, and I want to conduct some research and see code examples before I shape my idea.
I'm looking for interesting code examples that would demonstrate advanced usage of procfs (the Linux /proc file system). By interesting, I mean more than just reading a documented value.
My idea is to provide every process with an easy broadcast mechanism. For example, let's consider a process that runs multiple instances of rsync and wants to check the transfer status (how many bytes have been transfered so far) for each child. Currently, I don't know of any way that can be done.
I intend to provide the process with a minimal interface to write data to the procfs. That data would be placed under the PID directory. For example:
/procfs/1343/data_transfered/incoming
I can think of numerous advantage for this, mainly in the concurrency field.
By the way, if such a mechanism already exists, do tell...
Yes, I've written stuff that pokes around in /proc. I suspect you are unlikely to get linux kernel patches accepted that do anything with proc, unless they are just fixing something that is already there that was broken in some way.*
/sysfs seems to be where things are moving.
/proc was originally for process information, but a lot of misc. driver stuff ended up in there.
*well, maybe they'll take it if whatever you're doing has to do with processes, and isn't in a driver.
Go look at the source code for the procps package for code that uses /proc
http://github.com/tialaramex/leakdice/tree/master
Uses proc to figure out the memory address layout of a process, and dump random pages from its heap (for reasons which are explained in its documentation).