How to pass process-ID of active process while using Jprobe - linux-kernel

I'm trying to make a kernel module that takes the process-ID of an active process as an argument as module parameter, and tracks all the virtual addresses on which the target process faults.
While executing-
sudo ./module_name Parameter_1
What should be the Parameter_1 if I want to pass the ID of an active process.

Related

Does the Unix command Timeout also kill any children of the process?

The manual for the 'timeout' command makes it seem that it kills child processes if it is not used with the '--forground' option, but I can't find any explicit definition of how it behaves.
Does the timeout command also kill child processes/a process group of whatever command is used with it?
The GNU coreutils version of timeout can have its implementation viewed here.
Whether a process group is created (and killed as a whole) does indeed depend on whether --foreground is passed, as you have inferred from the documentation.
To be a bit more explicit:
When --foreground is not used, we call setpgid() to create a new process group, putting both the timeout command itself and the invoked command inside that group. When the timeout later occurs, kill() is passed 0 as the PID to kill, specifying that the entire process group should be targeted.
When --foreground is used, only the immediately forked PID is signaled, and not other members of the process group.

Bash - create multiple virtual guests in one loop

I'm working on a bash script (I just started learning bash) that involves creating virtual guests on a remote server. I do this by SSH'ing from server A to B and execute 2 different commands:
# create the images
$(ssh -n john#serverB.net "fallocate -l ${imgsize} /home/john/images/${imgname}")
and
# create the virtual machine
$(ssh -n john#serverB.net virt-install --bunch of options)
It is possible that these sets of commands have to be executed twice (if there need to be 2 virtual guests created) in a loop. When the second command is being run for the second time I sometimes get this error:
Domain installation still in progress.
This means I have to wait until the previous virtual guest is completed. How would I be able to do these operations in one loop? Can I run them asynchronously? Can I use threads? Or is there another way?
I have heard about the 'wait' command, but is that safe to use?
Check the man page for virt-install. You can use --wait=0 or --noautoconsole.
--wait=WAIT Amount of time to wait (in minutes) for a VM to complete its install. Without this option, virt-install will wait for the
console to close (not necessarily indicating the guest has shutdown),
or in the case of --noautoconsole, simply kick off the install and
exit. Any negative value will make virt-install wait indefinitely, a
value of 0 triggers the same results as noautoconsole. If the time
limit is exceeded, virt-install simply exits, leaving the virtual
machine in its current state.

How do I record all child processes spawned by an Ant script over time?

I inherited a legacy Ant-based build system and I'm trying to get a sense of its scope. I observed multiple jvm and junit tasks with fork=yes. It calls subant and similar tasks wildly. Occasionally, it just execs other processes.
I really don't want to search through 100s of scripts and reference documentation for every task to find possible-forking-behavior. I'd like to capture the child-process list while the build runs.
I managed to create a clean Vagrant + Puppet environment for builds and I can run the full build like so
$ cd /vagrant && $ANT_HOME/bin/ant
If I had to brute force something... I'd have a script kick off the build and capture child processes until the build is completed?
#!/bin/bash
$ANT_HOME/bin/ant &
while ps $!
do
sleep 1
ps --ppid $! >> build_processes
done
User Jayan recommended strace, specifically:
$ strace -f -e trace=fork ant
The -f limits tracing to fork system calls.
Trace child processes as they are created by cur-
rently traced processes as a result of the fork(2)
system call. The new process is attached to as soon
as its pid is known (through the return value of
fork(2) in the parent process). This means that such
children may run uncontrolled for a while (espe-
cially in the case of a vfork(2)), until the parent
is scheduled again to complete its (v)fork(2) call.
If the parent process decides to wait(2) for a child
that is currently being traced, it is suspended
until an appropriate child process either terminates
or incurs a signal that would cause it to terminate
(as determined from the child’s current signal dis-
position).
I can't find the trace=fork expression, but trace=process seems useful.
-e trace=process
Trace all system calls which involve process management. This is useful for watching the fork, wait, and exec steps of a process.
http://linuxcommand.org/man_pages/strace1.html
As ant is a java process, you can try to use byteman. In byteman script you define rules which are triggered when methods exec from java.lang.Runtime are executed.
You attach byteman to ant using ANT_OPTS env variable.

Clojure - Can I assign custom name to a process started using 'lein run'

Is there a way to assign a custom name to a process started using the command below
~lein run
The process stared by the above command is as displayed below -
~lsof -i tcp:8082
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
java 96029 <username> 89u IPv6 0xa04954e1ea972891 0t0 TCP *:us-cli (LISTEN)
It's possible though it gets a bit ugly and likely not worth the trouble
You would need to make a symlink to java with an alternate name, and modify lein to call that instead of calling java. You could do this by writing a lein plugin for instance. When Linux starts a process the name of the process it uses the name of the file from which the process was run as the name of the process thereafter, so you need to change the name of the file that gets run to create the process that will open the port, in this case "java".
If all you needed was an easy way to find either the process that opened the port or it's parent process then you could just make a script with a good name that called lein run. This would show up in the output from ps though not from lsof.

why init process is an user_space thread?

init process is created by 0 process and its pid is 1. I have known it's the ancestor of all the other processes except 0 process. init process creates idle process for each cpu in smp system and execute /sbin/init.But why it's a user_space process? It's behavior is more like a kernel-thread.
There is no process with pid 0.
/sbin/init is userspace program and it is the first process launched by kernel if kernel command line does not have init= as an argument.
It is idle task not a process and it is not user-space process. init process does not create idle-task.

Resources