System call killall (that kill all user processes)
Linux - KernelThis forum is for all discussion relating to the Linux kernel.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
System call killall (that kill all user processes)
i have used the code of sys_kill written in signal.c and make my own function and placed it also in signal.c make the appropriate changes in table , make it. but when i call it it returns successfully but no process is closed. i am stuck and ave no idea whats happening.
this is my function that i placed in signal.c after endif line
Firstly use [code] tags to enclose any code so that it is readable and able to be quoted by others in reply.
Secondly, have you started with a program to kill just one process as opposed to attempting to kill a bunch of processes on your system of which you may or may not know what they are and what they are doing?
The simplest call you can make it to use the kill() function because that is how you send a signal to another process, via C program:
Also note, not all user processes are pids > 1000....
User processes are usually identified by UID, not pid.
You should also know that other processes will not terminate until a context switch to them has occured. The resulting race condition gives more than enough time that a fork bomb can still lock the system... or that the system itself will start/restart user processes.
This is why killall is a user mode utility, not a kernel function.
we know kill function but this is our assignment and we are told not to use the kill function instead use its code.
so please rectify the problem in this code
the issue is when we use sys_kill(pid_t pid , int sig) directly it works.
the code then looks like this:
we know kill function but this is our assignment and we are told not to use the kill function instead use its code.
so please rectify the problem in this code
Obviously, since this is h-o-m-e-w-o-r-k, you need to be doing this yourself.
One suggestion that I would make here is that your logic might be a little cleaner if you first gather the list of pids to be killed, up to some reasonable size, and then loop through that list to kill the processes ... using existing system calls (internally) to do so.
Look carefully at the implementation of "kill()" to see exactly how it works. As others have noted, it basically marks the process for death: it does not, at that moment, dismantle it. All murders are accomplished by means of signals, which are asynchronous. It is correct for your code to return before the processes cease to exist.
"In the real world," there's a reason why kill-all is not implemented as a single system call. If the mass-murder is being done from user space, the assassin is regularly giving up control and being re-dispatched. There won't be too many corpses lying around at any particular instant.
However, this is a valid academic exercise. A good one, in fact.
Not being certain, but I think your selection of what to kill is flawed.
You process the current process tree walking back until the pid is <= 1000 - which is likely to mean GDM (assuming a windowing environment). The children will all likely to be Gnome (which you are checking for), and skipped, thus any
children of Gnome will also be skipped (they are in a tree belonging to Gnome). I expect this would be a single user workstation with only one login active - and only one Gnome process, thus there is only one child being looked at.
Could be wrong, but that is what it looks like to me.
One possibility you can test with is to have the system call return the number of processes signalled... It would confirm that no signals were sent.
I'm sure the assignment is specific and it just says, "all process IDs above 1000"
Bear in mind OP that you're supposed to work on your homework yourself and demonstrate a bit more than what you've shown. Sundialsvcs has some excellent suggestions for organization and I agree that you do need to organize your code better.
Further, in most systems there are services which if they are killed, they may be automatically restarted. Hence, some fundamental service may have a PID in excess of 1000. Heck, my PIDs have probably rolled over a few times, but right now I'm in the 11,000's for a new terminal.
If you are this lost, you should seek the advice of your instructor. They need to know that you, and possibly other students are struggling.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.