# variable type passed in call

**URL:** <https://discourse.julialang.org/t/variable-type-passed-in-call/15160>\
**Category:** General Usage\
**Created:** [September 19, 2018, 8:16am UTC](https://discourse.julialang.org/t/variable-type-passed-in-call/15160 "2018-09-19T08:16:05Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![einzigsue](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/einzigsue/32/7023_2.png) [@einzigsue](https://discourse.julialang.org/u/einzigsue)\
**Post date:** [September 19, 2018, 8:16am UTC](https://discourse.julialang.org/t/variable-type-passed-in-call/15160/1 "2018-09-19T08:16:05Z")

</div>

I want to get the task ID from the syscall function defined in libc as the function gettid() cannot be directly called in the same manner as getpid(). In C, it should be called from syscall function as

tid = syscall(SYS\_gettid)

where SYS\_gettid is defined as \_\_NR\_getid in the header bits/syscall.h with the type of long number.

I tried within julia

ccall((:syscall,“libc”), Int32, (Any,),“\_\_NR\_gettid”)

But it returns to -1 which indicate syscall returns to an error.

How should I do it?

---

<div class="post-metadata">

**Author:** ![mauro3](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mauro3/32/292_2.png) [@mauro3](https://discourse.julialang.org/u/mauro3)\
**Post date:** [September 19, 2018, 8:19am UTC](https://discourse.julialang.org/t/variable-type-passed-in-call/15160/2 "2018-09-19T08:19:25Z")

</div>

(I can’t answer your question, but you should read [PSA: how to quote code with backticks](https://discourse.julialang.org/t/psa-how-to-quote-code-with-backticks/7530))

---

<div class="post-metadata">

**Author:** ![nalimilan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nalimilan/32/147_2.png) [@nalimilan](https://discourse.julialang.org/u/nalimilan)\
**Post date:** [September 19, 2018, 8:20am UTC](https://discourse.julialang.org/t/variable-type-passed-in-call/15160/3 "2018-09-19T08:20:56Z")

</div>

`__NR_getid` isn’t a string, it’s a C preprocessor constant holding an integer. So you need to pass that integer. Unfortunately it seems to change depending on the platform:

```julia
$ grep NR_gettid -R /usr/include
/usr/include/asm-generic/unistd.h:#define __NR_gettid 178
/usr/include/asm-generic/unistd.h:__SYSCALL(__NR_gettid, sys_gettid)
/usr/include/asm/unistd_32.h:#define __NR_gettid 224
/usr/include/asm/unistd_64.h:#define __NR_gettid 186
/usr/include/asm/unistd_x32.h:#define __NR_gettid (__X32_SYSCALL_BIT + 186)
/usr/include/bits/syscall.h:#ifdef __NR_gettid
/usr/include/bits/syscall.h:# define SYS_gettid __NR_gettid

```

I’m not sure what’s the best solution to that. Probably just add conditions based on the platform.
