Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hello everyone,
I'm trying to get the PID value (the same it is shown in tLogCatcher) but I can't get the same one.
Let me explain: I'm using the following instruction to get the Process name, which includes its PID:
java.lang.management.ManagementFactory.getRuntimeMXBean().getName()
This will get me "11876@DESKTOP-LI4JPMJ"
To get the PID I'm doing as follows:
java.lang.management.ManagementFactory.getRuntimeMXBean().getName().substring(0, java.lang.management.ManagementFactory.getRuntimeMXBean().getName().indexOf("@"));
This will get me "11876"
But, in the same Job, the component tLogCatcher displays the following information:
+------------+-------------------------------+
| key | value |
+------------+-------------------------------+
| moment | 2024-05-30 20:23:54 |
| pid | yb9Lyl |
| root_pid | yb9Lyl |
| father_pid | yb9Lyl |
| context | Default |
| priority | 6 |
| type | Java Exception |
| origin | tFileOutputExcel_1 |
| message | java.io.FileNotFoundException:|
| code | 1 |
As you can see, these are not the same values.
Can anyone please let me know how to get the PID shown by the tLogCatcher component?
Thank you so much,
Rui
Hi,
If you want to retrieve the PID of a job inside a job, it is luckily very easy.
You just use pid as the value in any component.
And voila:
.------.
|tLogRow_1|
|=----=|
|pid |
|=----=|
|gq3o5u|
'------'
Hello
Open the Code tab to view the Java code generated by the Job. These lines of Java code generate a PID string with 6 length.
if (pid == null || "0".equals(pid)) {
pid = TalendString.getAsciiRandomString(6);
}
Regards
Shicong
Hi @Shicong_Hong ,
Thank you for replying.
I may have not made myself clear. I need to get the PID value while running the Job.
Thank you,
Rui
You can use tStatCatcher component to capture the job statistics information which includes the PID value, but if you want to customize the code to generate PID, it cannot be the same as the PID generated by the job, the job use function TalendString.getAsciiRandomString(6) to generates a random string with 6 length.
Good morning @Shicong_Hong ,
My wish is not to generate a PID code. But, instead, capture it to insert on a DB along with the records received by an API.
That's the challenge. To call an API, receive the results and insert them in a table along with the PID.
Thank you,
Rui
Hi,
If you want to retrieve the PID of a job inside a job, it is luckily very easy.
You just use pid as the value in any component.
And voila:
.------.
|tLogRow_1|
|=----=|
|pid |
|=----=|
|gq3o5u|
'------'
Link the result of API to a tMap and add extra job information in the output table, such as pid, jobName, projectName etc as you want. As Janterje said, to get the value of these job information, you can directly use the variable name in the expression field.
pid for PID
jobName for Job Name
projectName for Project Name
Really?!??!?!
Wow, thankyou so much. I really appreciate your help.
Cheers,
Rui
Thank you.
I will do that.
Thank you so much for the help.
Rui