Reputation: 105
To get process_id in Java, we use ProcessHandle.current().pid();
,. Jow we can get current-process-id in Systemverilog
?
Upvotes: -1
Views: 733
Reputation: 1
I believe you can use process::get_ranstate()
as a unique identifier for you
fork
begin : process_a
p = process::self();
int proc_id = p.get_randstate(); // Get a unique ID
`uvm_info("PROCESS_INFO", $sformatf("Process A started. ID = %0d", proc_id), UVM_MEDIUM)
#10;
end
begin : process_b
#5; // Ensure process A runs first
int proc_id = p.get_randstate(); // Get the same unique ID
`uvm_info("PROCESS_INFO", $sformatf("Process B checking process A. ID = %0d", proc_id), UVM_MEDIUM)
if (some_condition)
p.kill();
end
join_none
and the identifier can be smt like this:
randstate MSe2aab990e149a42b970a1cd680bde03f
Upvotes: 0
Reputation: 42738
Use the builtin process
class
begin
process pid;
pid = process::self();
...
end
See section 9.7 Fine-grain process control in the IEEE 1800-2017 SystemVerilog LRM
Upvotes: 1
Reputation: 12384
SystemVerilog does not have any facility to get 'pid' of its process. It provides an object to do limited process control in a system-independent way. You can check lrm 9.7 for available controls.
However, it is possible to get pid using DPI or PLI functions, using 'c' calls. But implementation could be system and simulator dependent.
For example, the following works with VCS on linux:
module pid();
import "DPI-C" function int getpid();
initial begin
$display("%d", getpid());
end
endmodule // pid
In the above getpid()
is a standard libc function which is callable from the simulator. It also seems to work with vcs, mentor, and cadence in EDA playground, but fails with aldec.
Since the function is globally defined, there is no need to define a dpi function body at least for the three simulators. However, you might need to define a different dpi function with a 'c' body to make it more portable.
Upvotes: 1