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_ADVISORY_INFO

_SC_ADVISORY_INFO

posix_fadvise, posix_fallocate, posix_memalign, posix_madvise

_POSIX_ASYNCHRONOUS_IO

_SC_ASYNCHRONOUS_IO

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

_POSIX_BARRIERS

_SC_BARRIERS

pthread_barrier_destroy, pthread_barrier_init, pthread_barrier_wait, pthread_barrierattr_destroy, pthread_barrierattr_init

POSIX_CHOWN_RESTRICTED

 

chown, fchown

_POSIX_CLOCK_SELECTION

_SC_CLOCK_SELECTION

pthread_condattr_getclock, pthread_condattr_setclock, clock_nanosleep

_POSIX_FSYNC

_SC_FSYNC

fsync

_POSIX_IPV6

_SC_IPV6

IPV6 is supported

_POSIX_JOB_CONTROL

_SC_JOB_CONTROL

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

_POSIX_MAPPED_FILES

_SC_MAPPED_FILES

mmap, msync, munmap

_POSIX_MEMLOCK

_SC_MEMLOCK

mlockall, munlockall

_POSIX_MEMLOCK_RANGE

_SC_MEMLOCK_RANGE

mlock, munlock

_POSIX_MEMORY_PROTECTION

_SC_MEMORY_PROTECTION

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

_POSIX_MONOTONIC_CLOCK

_SC_MONOTONIC_CLOCK

aio_suspend, clock_getres clock_gettime, clock_settime timer_create

_POSIX_PRIORITIZED_IO

_SC_PRIORITIZED_IO

aio_read, aio_write

_POSIX_PRIORITY_SCHEDULING

_SC_PRIORITY_SCHEDULING

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

_POSIX_SPAWN

 

posix_spawnattr_getschedparam, posix_spawnattr_getschedpolicy, posix_spawnattr_setschedparam, posix_spawnattr_setschedpolicy

_POSIX_RAW_SOCKETS

 

getsockopt, setsockopt

_POSIX_READER_WRITER_LOCKS

_SC_READER_WRITER_LOCKS

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

_POSIX_REALTIME_SIGNALS

_SC_REALTIME_SIGNALS

sigqueue, sigtimedwait, sigwaitinfo

_POSIX_REGEXP

_SC_REGEXP

regcomp, regerror, regexec, regfree

_POSIX_SAVED_IDS

_SC_SAVED_IDS

exec, kill, seteuid, setegid, setgid, setuid

_POSIX_SEMAPHORES

_SC_SEMAPHORES

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

_POSIX_SHARED_MEMORY_

_SC_SHARED_MEMORY_

mmap, munmap, shm_open,

OBJECTS

OBJECTS

shm_unlink

_POSIX_SHELL

_SC_SHELL

system

_POSIX_SPAWN

_SC_SPAWN

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

_POSIX_SPIN_LOCKS

_SC_SPIN_LOCKS

pthread_spin_destroy, pthread_spin_init, pthread_spin_lock, pthread_spin_trylock, pthread_spin_unlock

_POSIX_SPORADIC_SERVER

_SC_SPORADIC_SERVER

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

Affected functions are sched_ setparam, sched_setscheduler.

_POSIX_SYNCHRONIZED_IO

_SC_SYNCHRONIZED_IO

open, msync, fsync, fdata, sync

_POSIX_THREAD_ATTR_STACKADDR

_SC_THREAD_ATTR_STACKADDR

pthread_attr_getstack, pthread_attr_getstackaddr, pthread_attr_setstack, pthread_attr_setstackaddr

_POSIX_THREAD_ATTR_STACKSIZE

_SC_THREAD_ATTR_STACKSIZE

pthread_attr_getstack, pthread_attr_getstacksize, pthread_attr_setstack, pthread_attr_setstacksize

_POSIX_THREAD_CPUTIME

_SC_THREAD_CPUTIME

pthread_getcpuclockid, clock_getres, clock_gettime, clock_settime, timer_create

_POSIX_THREAD_PRIO_INHERIT

_SC_THREAD_PRIO_ INHERIT

pthread_mutexattr_getprotocol, pthread_mutexattr_setprotocol

_POSIX_THREAD_PRIO_PROTECT

_SC_THREAD_PRIO_PROTECT

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 (bhcompile@sizzler.build.redhat.com) (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

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net