Section 6.12. HP-UX System Calls and Linux Equivalents

6.12. HP-UX System Calls and Linux Equivalents

The 2.6.x release of Linux continues to offer wider support for POSIX APIs that were not previously supported in older Linux releases. This section and the section on Linux and HP-UX APIs compare HP-UX system calls and library APIs to their Linux equivalents. Linux 2.6 has come a long way in providing the best support for the most common as well as optional POSIX APIs.

6.12.1. Determining POSIX API Support

Depending on the installed version of Linux 2.6 on your platform, some optional POSIX APIs may not be supported. Upgrading to later releases of Linux 2.6 is the only option to get that support. An example of this is the optional POSIX APIs for message queues. Programatically, you can check API support by using the sysconf call.

Example 6-11 checks for _POSIX_MESSAGE_PASSING to check for message queue support. Note that Linux and HP-UX may return different values for the same POSIX option.

Example 6-11. Listing of samp_conf.c

#include <unistd.h> int main(int argc, char * argv[]) {     long ret = 0;     ret=sysconf(_SC_MESSAGE_PASSING);     switch (ret)     {         case -1:             printf("Invalid Option: errno %d\n", errno);             break;         case 0:             printf("Option MAY BE supported\n");             break;         default:             printf("Option supported %ld\n", ret);             break;     } } 

The samp_conf.c listing compiled and run on a Linux machine that supports _POSIX_MESSAGE_PASSING yields the following:

$ make samp_sysconf.c cc samp_sysconf.c  -o samp_sysconf $ ./samp_sysconf Option supported 200112 

The same program compiled and run on HP-UX yields the following:

$ ./samp_sysconf Option supported 1 

The POSIX API sysconf[45] allows an application to test at compile time or runtime whether certain options are supported. In the preceding runtime example, the argument to sysconf is the _SC equivalent of the POSIX option that the programmer is intereseted in finding (whether _POSIX_MESSAGE_PASSING is supported on the current Linux installation).

[45] See sysconf(3) for a more detailed description of the API.

Another programmatic way to check for POSIX options is shown in Example 6-12.

Example 6-12. Listing of test_posix.c

#include <unistd.h> #include <limits.h> #include <stdio.h> main() { #ifdef _POSIX_MESSAGE_PASSING      printf("  POSIX.4 Message Queues are supported.\n");      #ifdef _POSIX_MQ_OPEN_MAX       printf("   _POSIX_MQ_OPEN_MAX=%d Max # of message queues per process.\n",_POSIX_MQ_OPEN_MAX);      #else       printf("   No _POSIX_MQ_OPEN_MAX value exists.\n");      #endif      #ifdef _POSIX_MQ_PRIO_MAX       printf("   _POSIX_MQ_PRIO_MAX=%d Max # of message priorities.\n",_POSIX_MQ_PRIO_MAX);      #else       printf("   No _POSIX_MQ_PRIO_MAX value exists.\n");      #endif #else      printf("  POSIX.4 Message Queues are not supported.\n"); #endif } 

Example 6-12 compiled and run on a Linux machine that supports _POSIX_MESSAGE_PASSING yields the following output:

$ make test_posix cc   test_posix.c  -o test_posix $ ./test_posix   POSIX.4 Message Queues are supported.    _POSIX_MQ_OPEN_MAX=8 Max # of message queues per process.    _POSIX_MQ_PRIO_MAX=32 Max # of message priorities. 

The same program compiled and run on HP-UX v11 yields the following output:

$ ./test_posix   POSIX.4 Message Queues are supported.    _POSIX_MQ_OPEN_MAX=8 Max # of message queues per process.    _POSIX_MQ_PRIO_MAX=32 Max # of message priorities. 

Table 6-20 shows the different POSIX options[46] and their _SC equivalents along with the corresponding APIs that are affected if the POSIX option is supported.

[46] See posixoptions(7) on the Linux man pages for more information.

Table 6-20. POSIX Options and Corresponding Affected APIs

POSIX Option

_SC Equivalent

Affected APIs



posix_fadvise, posix_fallocate, posix_memalign, posix_madvise



aio_cancel, aio_error, aio_read, aio_return, aio_suspend, aio_write, lio_listio



pthread_barrier_destroy, pthread_barrier_init, pthread_barrier_wait, pthread_barrierattr_destroy, pthread_barrierattr_init



chown, fchown



pthread_condattr_getclock, pthread_condattr_setclock, clock_nanosleep






IPV6 is supported



setpgid, tcdrain, tcflush, tcgetpgrp, tcsendbreak, tcsetattr, tcsetpgrp



mmap, msync, munmap



mlockall, munlockall



mlock, munlock



mq_close, mq_getattr, mq_notify, mq_open, mq_receive, mq_send, mq_setattr, mq_unlink



aio_suspend, clock_getres clock_gettime, clock_settime timer_create



aio_read, aio_write



sched_get_priority_max, sched_get_priority_min, sched_getparam, sched_getscheduler, sched_rr_get_interval, sched_setparam, sched_setscheduler, sched_yield



posix_spawnattr_getschedparam, posix_spawnattr_getschedpolicy, posix_spawnattr_setschedparam, posix_spawnattr_setschedpolicy



getsockopt, setsockopt



pthread_rwlock_destroy, pthread_rwlock_init, pthread_rwlock_rdlock, pthread_rwlock_tryrdlock, pthread_rwlock_trywrlock, pthread_rwlock_unlock, pthread_rwlock_wrlock pthread_rwlockattr_destroy, pthread_rwlockattr_init



sigqueue, sigtimedwait, sigwaitinfo



regcomp, regerror, regexec, regfree



exec, kill, seteuid, setegid, setgid, setuid



sem_close, sem_destroy, sem_getvalue, sem_init, sem_open, sem_post, sem_trywait, sem_unlink, sem_wait



mmap, munmap, shm_open,









posix_spawn, posix_spawn_file_actions_ addclose, posix_spawn_file_actions_ adddup2, posix_spawn_file_actions_ addopen, posix_spawn_file_actions_ destroy, posix_spawn_file_actions_init, posix_spawnattr_destroy, posix_spawnattr_getsigdefault, posix_spawnattr_getflags, posix_spawnattr_getpgroup, posix_spawnattr_getsigmask, posix_spawnattr_init, posix_spawnattr_setsigdefault, posix_spawnattr_setflags, posix_spawnattr_setpgroup, posix_spawnattr_setsigmask, posix_spawnp



pthread_spin_destroy, pthread_spin_init, pthread_spin_lock, pthread_spin_trylock, pthread_spin_unlock



The scheduling policy SCHED_SPORADIC is supported. This option implies the _POSIX_PRIORITY_SCHEDULING option.

Affected functions are sched_ setparam, sched_setscheduler.



open, msync, fsync, fdata, sync



pthread_attr_getstack, pthread_attr_getstackaddr, pthread_attr_setstack, pthread_attr_setstackaddr



pthread_attr_getstack, pthread_attr_getstacksize, pthread_attr_setstack, pthread_attr_setstacksize



pthread_getcpuclockid, clock_getres, clock_gettime, clock_settime, timer_create



pthread_mutexattr_getprotocol, pthread_mutexattr_setprotocol



pthread_mutex_getprioceiling, pthread_mutex_setprioceiling, pthread_mutexattr_ getprioceiling, pthread_mutexattr_getprotocol

6.12.2. Determining Linux Kernel Version

When new Linux versions are announced, sometimes the announcement mentions support for new features or optional standards. At the time of this writing, Linux version 2.6.6 was announced. That announcement mentioned support for message queues (that is, _POSIX_MESSAGE_PASSING).

The easiest way to determine the version of the running Linux kernel is to cat the file /proc/version.

The following is from a SUSE 9.1 installation on IA32:

$ cat /proc/version Linux version 2.6.4-52-smp (geeko@buildhost) (gcc version 3.3.3 (SuSE Linux)) #1 SMP Wed Apr 7 02:11:20 UTC 2004 

Running Example 6-12 on this Linux server yields the following:

$ ./test_posix POSIX.4 Message Queues are not supported. 

This version of Linux does not support message queues.

The following is from a RHEL4 running on a POWER5:

$ cat /proc/version Linux version 2.6.9-5.EL ( (gcc version 3.4.3 20041212 (Red Hat 3.4.3-9.EL4)) #1 SMP Wed Jan 5 19:23:58 EST 2005 

Running Example 6-12 on this Linux server yields the following:

$ ./test_posix   POSIX.4 Message Queues are supported.    _POSIX_MQ_OPEN_MAX=8 Max # of message queues per process.    _POSIX_MQ_PRIO_MAX=32 Max # of message priorities. 

This version of Linux does support message queues.

During the analysis phase of the porting project, porting engineers may run some tools that look for API incompatibilities between HP-UX and Linux. Some may try to build the application on Linux and look through the build log for errors. However, sometimes tools and build logs are not enough. When an incompatibility is found, you may want to know whether there is an equivalent on Linux (see Table C-3 in appendix C, "HP-UX to Linux Reference Tables").

UNIX to Linux Porting. A Comprehensive Reference
UNIX to Linux Porting: A Comprehensive Reference
ISBN: 0131871099
EAN: 2147483647
Year: 2004
Pages: 175 © 2008-2017.
If you may any questions please contact us: