I am writing a Linux C program that will be executed as init. It will eventually need to shut down the system. I have code for unmounting all the filesystems and actually turning off the system; now I just need a way for it to send SIGTERM to all processes, sleep(5), then send SIGKILL to any remaining processes. Answer If
Tag: process
Does linux process VSZ equal 0 mean kernel space application?
I notice some process always have VSZ as 0 how to understand why they have 0 VSZ? Answer VSZ is the Virtual Memory Size. It includes all memory that the process can access, including memory that is swapped out, memory that is allocated, but not used, and memory that is from shared libraries. So, the top command screenshot you shared
Multiprocessing Process os.system(‘kill -9 {0}’.format(pid)) fails on Linux
when I use terminate in linux with python, I found the way to close the progress in the way os.system(‘kill -9 {0}’.format(pid)), but it failed. My code is to run two progress.when the first progress finished, I want the second progress close too (the second progress it’s self running all the time if you don’t close it). Answer Make sure
Changing nice value of a process has no effect in Linux
I read about APUE 3rd, 8.16 Process Scheduling, there is an example written to verify that changing nice value of a process will affect its priority, I rewrite the code like below: And the result of the example is shown below: NZERO = 20 parent nice:20 child nice:20, adjusted by 0 child now nice:20 parent count:601089419 child count:603271014 Looks like
How to make parent process invoke wait when child exits with parent unblocked in Linux?
Here is an example, waitpid system call will block parent process until child process exits: What I want to achieve is parent process won’t be blocked, this can be done by using signal, so I changed my code: But another problem comes, if child exit before signal(SIGCHLD, handler), child will be a zombie, we can’t expect the child exit after
System call that shows processes filtered by their status
I am making a system call that loops through every process with a certain status (passed to the syscall as a parameter) and show their Name, PID, UID and the name of their children. This is what I have so far: This prints all of the system’s processes and their children, completely ignoring the condition if(task->state == state), which is
How many ways will a process be terminated in Linux?
I’m reading Advanced Programming in the Unix Environment 3rd Edn, ยง7.3, Process Termination, the following statement make me confused: There are eight ways for a process to terminate. Normal termination occurs in five ways: Return from main Calling exit Calling _exit or _Exit Return of the last thread from its start routine (Section 11.5) Calling pthread_exit (Section 11.5) from the
linux c: what’s the common use case of “sched_setaffinity” function? I don’t find it useful
The operating system is able to determine how to arrange difference processes/threads onto different cpu cores, the os scheduler does the work well. So when do we really need to call functions like sched_setafficity() for a process, or pthread_setaffinity_np() for a pthread? It doesn’t seem to be able to raise any performance dramatically, if it can, then I suppose we
Irregular result in zombie example
I have problems with understanding the behavior of this code: When running in a Unix shell I get this result: But sometimes its only giving me this result without any shell prompt: I know it can be solved with wait() function in parent process. But I like to know: Why is result irregular? Could someone please explain what happening? Child
Father-child process use pipe to talk, hangs after “execlp”, why?
I’ve got a simple text file called “tmp” under current directory, I wish to “cat” this file and then “sort” it, I want to use a c program to act like pipe “|” so I tried to use a father/child talk to do this. Unexpectedly, the program hangs after “cat”, like below: g++ to compile and run this file, after